如何解析2013-03-13T20:59:31 + 0000日期字符串到日期 [英] How parse 2013-03-13T20:59:31+0000 date string to Date
问题描述
如何在Date对象中解析此日期字符串 2013-03-13T20:59:31 + 0000 ?
How to parse this date string 2013-03-13T20:59:31+0000 in Date object?
我试过这个方式,但不工作。
I tryed on this way but dont work.
DateFormat df = new SimpleDateFormat("YYYY-MM-DDThh:mm:ssTZD");
Date result = df.parse(time);
推荐答案
DateFormat df = new SimpleDateFormat (yyyy-MM-dd'T'hh:mm:ssZ);
年份为小写y。
输入中与日期无关的任何字符(如 2013-03-13T20:59:31 + 0000
中的'T'应该是引用''
。
Year is lower case y.
Any characters that are in the input which are not related to the date (like the 'T' in 2013-03-13T20:59:31+0000
should be quoted in ''
.
有关已定义模式字母的列表,请参阅文档
For a list of the defined pattern letters see the documentation
分析检查给定日期是否为您指定的格式。
在检查后以下列方式打印特定格式的日期:
Parse checks that the given date is in the format you specified. To print the date in a specific format after checking see below:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
Date result;
try {
result = df.parse("2013-03-13T20:59:31+0000");
System.out.println("date:"+result); //prints date in current locale
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(sdf.format(result)); //prints date in the format sdf
}
这篇关于如何解析2013-03-13T20:59:31 + 0000日期字符串到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!