将日期时间转换为24小时格式 [英] converting date time to 24 hour format
本文介绍了将日期时间转换为24小时格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从服务器获取的时间就像 2011年7月27日8:35:29 AM
。
The time I get from the server is like Jul 27, 2011 8:35:29 AM
.
我想将其转换为 yyyy-MM-dd HH:mm:ss
。
我也希望转换时间为24小时格式。任何人都可以解决这个问题。我想得到的输出就像 2011-07-27 08:35:29
I also want the converted time to be in 24 hour format. Can any one give solution to this problem. The output I want to get is like 2011-07-27 08:35:29
推荐答案
尝试这样:
String dateStr = "Jul 27, 2011 8:35:29 AM";
DateFormat readFormat = new SimpleDateFormat( "MMM dd, yyyy hh:mm:ss aa");
DateFormat writeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = readFormat.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
if (date != null) {
String formattedDate = writeFormat.format(date);
}
这篇关于将日期时间转换为24小时格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文