日期格式化android系统 [英] Date formating in android
本文介绍了日期格式化android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我想要解析一个字符串到日期的'2013年11月15日格式的问题,但我不能这样做,使用MMMM D,YYYY中的SimpleDateFormat类。请提出任何解决方案有关的相同。
I have a problem that I want to parse a String to Date in 'November 15, 2013' format but I unable to do that using MMMM D, YYYY in SimpleDateFormat Class. Please suggest any solution regarding to the same.
code:
SimpleDateFormat formatter = new SimpleDateFormat("MMMM DD, yyyy");
try {
Date publishedDate = formatter.parse(pictureDirectory.replace(str, ""));
hashMap.put(publishedDate, getImageFromSdCard(picturePath));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
它总是返回周五11月15日00:00:00北京时间2013。
It always returns 'Fri Nov 15 00:00:00 IST 2013'.
先谢谢了。
推荐答案
看看从Android的例子在的 SimpleDateFormat的。
Take a look at the example from Android at SimpleDateFormat.
String[] formats = new String[] {
"yyyy-MM-dd",
"yyyy-MM-dd HH:mm",
"yyyy-MM-dd HH:mmZ",
"yyyy-MM-dd HH:mm:ss.SSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ",
};
for (String format : formats) {
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
}
输出:
yyyy-MM-dd 1969-12-31
yyyy-MM-dd 1970-01-01
yyyy-MM-dd HH:mm 1969-12-31 16:00
yyyy-MM-dd HH:mm 1970-01-01 00:00
yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800
yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000
yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800
yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000
yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800
yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000
这篇关于日期格式化android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文