SimpleDateFormat的返回24小时日期:如何获得12个小时的时间? [英] SimpleDateFormat returns 24-hour date: how to get 12-hour date?
本文介绍了SimpleDateFormat的返回24小时日期:如何获得12个小时的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想当前时间米利斯,然后将其存储在12个小时的格式,但与这片code我越来越24小时格式的时间。
长timeInMillis = System.currentTimeMillis的();
日历吹响--- = Calendar.getInstance();
cal1.setTimeInMillis(timeInMillis);
SimpleDateFormat的日期格式=新的SimpleDateFormat(DD / MM / YYYY HH:MM:SS);
dateforrow = dateFormat.format(cal1.getTime());
任何人可以提出修改建议,以获得想要的结果?
解决方案
修改 HH
到 HH
为
长timeInMillis = System.currentTimeMillis的();
日历吹响--- = Calendar.getInstance();
cal1.setTimeInMillis(timeInMillis);
SimpleDateFormat的日期格式=新的SimpleDateFormat(
DD / MM / YYYY HH:MM:SS);
dateforrow = dateFormat.format(cal1.getTime());
注意 DD / MM / YYYY
- 会给你的分的代替的月的
I want current time in millis and then to store it in 12 hour format but with this piece of code I am getting 24 hour format time.
long timeInMillis = System.currentTimeMillis();
Calendar cal1 = Calendar.getInstance();
cal1.setTimeInMillis(timeInMillis);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss a");
dateforrow = dateFormat.format(cal1.getTime());
can anybody suggest modifications to get the desired results?
解决方案
Change HH
to hh
as
long timeInMillis = System.currentTimeMillis();
Calendar cal1 = Calendar.getInstance();
cal1.setTimeInMillis(timeInMillis);
SimpleDateFormat dateFormat = new SimpleDateFormat(
"dd/MM/yyyy hh:mm:ss a");
dateforrow = dateFormat.format(cal1.getTime());
Note that dd/mm/yyyy
- will give you minutes instead of the month.
这篇关于SimpleDateFormat的返回24小时日期:如何获得12个小时的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文