日期格式中的android [英] Date Format in android
本文介绍了日期格式中的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的格式为2011年8月1日上午04时06日期字符串。我希望将其转换到格式2011-08-1T16的日期字符串:06:00-04:00使用日期格式。我现在用的是code
I have date string of the format 8/1/2011 04:06 am. I want it to convert it in to the date string of the format 2011-08-1T16:06:00-04:00 using DateFormat. I am using the code
private String formatDate(String date) {
SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
Date dateObj = null;
try {
dateObj = curFormater.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String format = "yyyy-MM-dd'T'HH:mmZ";
String date = (String) DateFormat.format(format, dateObj);
return date;
}
但它返回字符串2011-01-08THH:37Z。
But it returns the String 2011-01-08THH:37Z.
任何一个可以请帮我这个?
Can any one please help me with this?
推荐答案
尝试更换这样的:
String date = (String) DateFormat.format(format, dateObj);
这一点:
curFormater = new SimpleDateFormat(format);
date = curFormater.format(dateObj);
此外,考虑到你的例子是有点误导:
Also, take into account that your example is a bit misleading:
上午04点○六
不应该 16:06:00-04:00
,但下午四时06
应 16:06:00-04:00
这篇关于日期格式中的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文