如何更改日期格式的Android? [英] How to change the date format in android?
本文介绍了如何更改日期格式的Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是显示日期和时间格式为 2013年6月18号12点41分24秒。
但是,我怎么能更改,如格式的 18军,2013下午12时41
我该如何改变机器人?格式
i am displaying the date and time format is 2013-06-18 12:41:24.
But how can i change the format like 18-jun-2013 12:41 pm
how do I change the format in android?
推荐答案
下面正code
public String parseDateToddMMyyyy(String time) {
String inputPattern = "yyyy-MM-dd HH:mm:ss";
String outputPattern = "dd-MMM-yyyy h:mm a";
SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern);
SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);
Date date = null;
String str = null;
try {
date = inputFormat.parse(time);
str = outputFormat.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
return str;
}
文档:的SimpleDateFormat | Android开发者
这篇关于如何更改日期格式的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文