Java DATE解析 [英] Java DATE Parsing
本文介绍了Java DATE解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个愚蠢的问题 java.util.Date
。
我有这行代码,但我不明白为什么这个日期用这种格式是不可解析的。
I have this line of code, but I don´t understand why this date is unparseable with this format.
public class TestTime {
public static void main(String[] args) {
final String DATE_FORMAT = "EEE MMM dd HH:mm:ss zzz yyyy";
String date = "Sat Dec 31 10:00:00 CET 2011";
SimpleDateFormat dFormat = new SimpleDateFormat(DATE_FORMAT);
Date lDate = null;
try {
lDate = dFormat.parse(date);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
推荐答案
如果您的系统使用英语以外的语言环境,则需要使用此构造函数:
If your system uses a locale other than English you need to use this constructor:
SimpleDateFormat(DATE_FORMAT,Locale.ENGLISH);
如果这不是问题,您应该使用相同的格式化程序格式化日期并将输出与你的输入字符串。
If this is not the problem, you should format a date using the same formatter and compare the output to your input string.
这篇关于Java DATE解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文