我有时间以毫秒为单位。 1308700800000
;我需要将其转换为类似 Jun 9'11 at 02:15 PM
的格式。
我试过用
SimpleDateFormat format = new SimpleDateFormat("MMM D'\''YY");
但我得到一个异常(exception):
Caused by: java.lang.IllegalArgumentException: Unterminated quote
如有任何帮助,我们将不胜感激。
最佳答案
从异常消息中可以清楚地看出问题出在您的格式字符串上,尤其是单引号部分。
查看 documentation ,我们可以看到:
Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote.
因此我相信您的格式(对于那个日期部分,根据您现有的示例)可以像
new SimpleDateFormat("MMM d''yy")
应该没有必要涉及反斜杠。
关于java - 以毫秒为单位的自定义日期和时间字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466017/