Java日历时钟返回12小时格式 [英] Java Calendar Hour of Day Returning 12 Hour Format

查看:417
本文介绍了Java日历时钟返回12小时格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java文档中, Calendar.HOUR 应该以12小时格式返回小时, Calendar.HOUR_OF_DAY 应该返回24小时格式的小时,但是这两个格式都以12小时格式返回。

In the Java docs, Calendar.HOUR is supposed to return the hour in the 12 hour format, and Calendar.HOUR_OF_DAY is supposed to return the hour in the 24 hour format, but both of these are returning in the 12 hour format.

我的代码:

Calendar rightNow = Calendar.getInstance();
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
System.out.println("hour: " + hour);

有一个类似于我的问题,但有一个特定的时间, m尝试用当前时间这样做。这个问题在这里 java HOUR和HOUR_OF_DAY都回来了12小时时间

There is a question that is similar to mine already, but there's is for a specific time and I'm attempting to do this with the current time. That question is here java HOUR and HOUR_OF_DAY both returning 12-hr time

编辑

如果重要的话,这是发生在Windows上的Eclipse,Windows上的cmd.exe和Ubuntu上的Terminal上。

If it matters, this is happening within Eclipse on Windows, within cmd.exe on Windows, and Terminal on Ubuntu.

编辑2

现在我觉得很蠢...我没有意识到我有多个实例调用当前时间,我在看错了,这是HOUR_OF_DAY,但我在控制台中看到的一个正在发布的只是HOUR ...感谢您的帮助在评论和编辑我自己的帖子这导致我实现我的错误

Now I feel dumb... I didn't realize that I had multiple instances of calling the current time, and I was looking at the wrong one, which was HOUR_OF_DAY, but the one I was seeing in the console were being posted by just HOUR... Thanks for the help in the comments and the edit of my own post that led me to realize my mistake

推荐答案

检查我的代码中引用日历对象的所有区域尝试获取小时是问题。我在三个不同的位置做到这一点,但只修改了三个之一,这就是为什么我的更新似乎没有生效

Checking all the areas in my code that referenced the Calendar object to try to get the hours was the problem. I did this in three different locations but only modified one of the three, which is why my updates didn't seem to take effect

这篇关于Java日历时钟返回12小时格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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