这是什么日期格式? 2011-08-12T20:17:46.384Z [英] What is this date format? 2011-08-12T20:17:46.384Z
问题描述
我有以下日期: 2011-08-12T20:17:46.384Z
。这是什么格式?我试图用Java 1.4来解析它,通过 DateFormat.getDateInstance()。parse(dateStr)
我正在获得
I have the following date: 2011-08-12T20:17:46.384Z
. What format is this? I'm trying to parse it with Java 1.4 via DateFormat.getDateInstance().parse(dateStr)
and I'm getting
java.text.ParseException:不可稀释的日期:2011-08-12T20:17:46.384Z
java.text.ParseException: Unparseable date: "2011-08-12T20:17:46.384Z"
我想我应该使用 SimpleDateFormat 进行解析,但是我必须首先知道格式字符串。到目前为止,我所有的都是 yyyy-MM-dd
,因为我不知道什么是 T
在这个字符串 - 某个时区相关?该日期字符串来自 lcmis:downloadedOn 标签/ Files_CMIS_download_history_media_typerel =noreferrer>文件CMIS下载历史媒体类型。
I think I should be using SimpleDateFormat for parsing, but I have to know the format string first. All I have for that so far is yyyy-MM-dd
, because I don't know what the T
means in this string--something time zone-related? This date string is coming from the lcmis:downloadedOn
tag shown on Files CMIS download history media type.
推荐答案
T只是一个文字分隔日期与时间,Z表示零小时偏移也称为祖鲁时间(UTC)。如果您的字符串始终具有Z,您可以使用:
The T is just a literal to separate the date from the time, and the Z means "zero hour offset" also known as "Zulu time" (UTC). If your strings always have a "Z" you can use:
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
或使用 Joda时间,可以使用 ISODateTimeFormat.dateTime()
。
Or using Joda Time, you can use ISODateTimeFormat.dateTime()
.
这篇关于这是什么日期格式? 2011-08-12T20:17:46.384Z的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!