将24小时转换为12小时? [英] Converting 24hour time to 12hour time?
本文介绍了将24小时转换为12小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我正在使用Android应用程序,我正在尝试弄清楚如何将24小时时间转换为12小时。
Hello I am using an android application and I am trying to figure out how to convert a 24 hour time to a 12hour time.
Example
24 hour format 12:18:00
to
12 hour format 12:18pm
推荐答案
尝试使用 SimpleDateFormat
:
String s = "12:18:00";
DateFormat f1 = new SimpleDateFormat("HH:mm:ss"); //HH for hour of the day (0 - 23)
Date d = f1.parse(s);
DateFormat f2 = new SimpleDateFormat("h:mma");
f2.format(d).toLowerCase(); // "12:18am"
这篇关于将24小时转换为12小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文