将字符串格式的日期解析为 GregorianCalendar 的最简单方法
问题描述:
我有以下日期:
2011-10-07T08:51:52.006Z
现在我想将其解析为 GregorianCalendar.有没有比使用子字符串并将它们解析为整数更简单的方法?
Now I want to parse it into a GregorianCalendar. Is there an easier way to do it than using substrings and parsing them to Integers?
时间字符串中的 Z 是什么?
And what is the Z in the time string?
我尝试使用 SimpleDateFormat 解析它,但我找不到日期字符串中 T 的解释.
I tried to parse it using SimpleDateFormat, but I can´t find a explanation for the T in the date String.
答
DateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
Date date = format.parse( "2011-10-07T08:51:52.006Z" );
Calendar calendar = new GregorianCalendar();
calendar.setTime( date );