[英]Moment.js Date parse exception in java
I am using this format to getting a date from a user on a form 我正在使用这种格式从表单上的用户那里获取日期
moment().format('MMMM Do YYYY, h:mm:ss a');
getting this 得到这个
// May 30th 2018, 11:38:58 am
but when try to format this date in java like below getting a parse exception 但是当尝试使用以下格式在Java中格式化此日期时,出现解析异常
SimpleDateFormat ft = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a", Locale.US);
Date date= ft.parse(jsonObject.get("date").getAsString());
can anyone tell me whats wrong , any working example 谁能告诉我有什么问题,任何可行的例子
Just replace th
, it is not mandatory 只需更换
th
,它不是强制性的
SimpleDateFormat ft = new SimpleDateFormat("MMM dd yyyy, hh:mm:ss a", Locale.US);
String dateString = "May 30th 2018, 11:38:58 am";
Date date= ft.parse(dateString
.replaceAll("(?<=\\d)(st|nd|rd|th)", "")
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.