24小时时钟不工作的日期格式的android [英] 24 hour clock not working in dateformat android
问题描述
我已经在我需要24小时制执行日期转换的应用程序。 这是我的code。
i have made an application in which i need to perform date conversion in 24 hour format. Here is my code.
GregorianCalendar c = new GregorianCalendar(Locale.GERMANY);
c.set(2011, 04, 29,0,0,0);
String cdate = (String) DateFormat.format("yyyy-MM-dd HH:mm:ss", c.getTime());
Log.i(tag,cdate);
现在,当我点击这里我的日志是输出:
now when i check my LOG here is the output:
12月4号至22日:44:15.956:信息/ GridCellAdapter(30248):2011-04-29 HH:00:00
04-22 12:44:15.956: INFO/GridCellAdapter(30248): 2011-04-29 HH:00:00
为什么是小时现场没有得到设置。我已明确地过去了0时,我正在日历对象,它仍然是在日志显示HH。 我已经尝试过,而通过HH,正被确定,但HH不被设置。
why is the hour field not getting set. i have explicitly passed 0 when i was making the calendar object, still it is display HH in the LOG. i have tried while passing hh, that is being set, but HH is not being set.
可能是什么问题?
感谢你在前进。
推荐答案
请尝试使用的SimpleDateFormat ,日期格式的子类。这可能会纠正你遇到的问题。
Try using SimpleDateFormat, a subclass of DateFormat. That might correct the problems you're having.
例如。打印当前日期时间
e.g. to print current datetime
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_H-mm-ss",Locale.US);
String formattedDateString = dateFormat.format(new java.util.Date());
// result is something like "2013-02-14_18-44-15"
这篇关于24小时时钟不工作的日期格式的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!