自定义日期和时间字符串(以毫秒为单位)
我有时间以毫秒为单位。 1308700800000
;我需要将其转换为 Jun 9'11 at 02:15 PM
之类的内容。
我尝试使用,
SimpleDateFormat format = new SimpleDateFormat("MMM D'\''YY");
但出现异常:
Caused by: java.lang.IllegalArgumentException: Unterminated quote
任何帮助将不胜感激。
I have time in milliseconds for ex. 1308700800000
; I need to convert it to something like Jun 9'11 at 02:15 PM
.
I tried using
SimpleDateFormat format = new SimpleDateFormat("MMM D'\''YY");
but i get an exception:
Caused by: java.lang.IllegalArgumentException: Unterminated quote
Any help would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从异常消息中可以清楚地看出,问题出在格式字符串上,特别是单引号部分周围。
查看文档,我们可以看到:
因此,我相信您的格式(对于该日期部分,根据您现有的示例)可以简单到
不需要涉及反斜杠。
It's clear from the exception message that the problem is going to lie with your format string, in particular around the single quote part.
Looking at the documentation, we can see that:
Thus I believe your format (for that date part, as per your existing example) can be as simple as
There should be no need to get backslashes involved.
尝试:
打印:
try:
prints:
Andrzej 是对的,但 Caps D 和 Y 不适合你。阅读文档,但是
那应该有效:
Andrzej is right, but Caps D and Y won't work for you. Read the doc, but
that should work: