24小时制时钟不工作在日期格式android [英] 24 hour clock not working in dateformat android

查看:134
本文介绍了24小时制时钟不工作在日期格式android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经提出了一个应用程序,我需要以24小时格式执行日期转换。
这是我的代码。

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);

现在当我查看我的LOG这里是输出:

now when i check my LOG here is the output:

04-22 12:44:15.956:INFO / GridCellAdapter(30248):2011-04-29 HH:00:00

04-22 12:44:15.956: INFO/GridCellAdapter(30248): 2011-04-29 HH:00:00

为什么是小时字段未设置。当我制作日历对象时,我已经明确地通过0,而在LOG中显示HH。
i在通过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 ,DateFormat的子类。这可能会纠正您遇到的问题。

Try using SimpleDateFormat, a subclass of DateFormat. That might correct the problems you're having.

例如打印当前日期时间

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆