如何转换日期格式的android [英] how to convert date format in android
本文介绍了如何转换日期格式的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到日期为字符串 YYYY / MM / DD HH:MM:SS
format.I想把它变成了毫米/ DD / YYYY HH:MM:SS
,也将显示AM和PM我该怎么办this.please帮助我
I am getting date into string in YYYY/MM/DD HH:MM:SS
format.I want to change it into the mm/dd/yyyy HH:mm:ss
and also it will show AM and PM how can I do this.please help me
感谢您
推荐答案
要获得AM PM和12小时日期格式使用 HH:MM:SS
作为字符串格式化WHERE HH
是12小时制和 A
是AM PM格式。
To get AM PM and 12 hour date format use hh:mm:ss a
as string formatter WHERE hh
is for 12 hour format and a
is for AM PM format.
注意:的HH是 24
小时,HH是 12
小时日期格式
Note: HH is for 24
hour and hh is for 12
hour date format
SimpleDateFormat formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss a");
String newFormat = formatter.format(testDate);
示例
String date = "2011/11/12 16:05:06";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd HH:MM:SS");
Date testDate = null;
try {
testDate = sdf.parse(date);
}catch(Exception ex){
ex.printStackTrace();
}
SimpleDateFormat formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss a");
String newFormat = formatter.format(testDate);
System.out.println(".....Date..."+newFormat);
这篇关于如何转换日期格式的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文