将字符串格式的日期解析为 GregorianCalendar 的最简单方法 [英] Easiest way to parse date in String format to GregorianCalendar

查看:36
本文介绍了将字符串格式的日期解析为 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 );

这篇关于将字符串格式的日期解析为 GregorianCalendar 的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆