如何通过在Android中Java的小时,分​​钟和秒日历对象 [英] how to pass hour, minute and second in calendar object in android java

查看:178
本文介绍了如何通过在Android中Java的小时,分​​钟和秒日历对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我需要执行日期转换的应用程序。
这里是我的code。

i have made an application in which i need to perform date conversion. 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:

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。
可能是什么问题?

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. what could be the problem?

感谢您提前。

推荐答案

使用小写HH:

String cdate = (String) DateFormat.format("yyyy-MM-dd hh:mm:ss", c.getTime());

这篇关于如何通过在Android中Java的小时,分​​钟和秒日历对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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