简体   繁体   English

您如何在Java中解析此日期格式?

[英]How do you parse this date format in java?

Simple question: what format should I use with this date? 一个简单的问题:此日期应使用哪种格式?

2011-10-09T05:06:03.000000Z

This one does not work: 这一项不起作用:

"yyyy-MM-dd'T'HH:mm:ssZZ"

From the manual: "The timestamp is calculated from epoch_ticks (zulu), format=%Y-%m-%dT%H:%M:%S.%fZ" 在手册中:“时间戳是根据epoch_ticks(zulu)计算的,格式=%Y-%m-%dT%H:%M:%S.%fZ”

I think the short answer is "you can't". 我认为简短的答案是“你不能”。 For some reason Java does not support "Z" as a time zone identifier. 由于某种原因,Java不支持将“ Z”用作时区标识符。 You can do a workaround like this though: 不过,您可以执行以下解决方法:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = df.parse("2011-10-09T05:06:03.000000Z");

This assumes that the date will be in UTC and ignores the Z. 假设日期将采用UTC,并且忽略Z。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM