- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
一个简单的问题,但我找不到它:
HOUR_OF_DAY 的范围是 0 到 23,还是 1 到 24?
我想要一个随机的 HOUR_OF_DAY,我需要吗:
int randomHour = (int) (Math.random()*24);
或
int randomHour = (int) (Math.random()*24+1);
最佳答案
来自 the documentation :
Field number for get and set indicating the hour of the day.
HOUR_OF_DAY
is used for the 24-hour clock. E.g., at 10:04:15.250 PM theHOUR_OF_DAY
is 22.
如果晚上 10:04:15.250 是 HOUR_OF_DAY
22,则范围为 0
- 23
。如果是 1
到 24
,晚上 10 点。将是 23 岁。这在很多层面上都是错误的。 :-)
关于java - HOUR_OF_DAY 的范围是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23168805/
我在 Windows 和 Solaris 机器上运行相同的 Java 代码。有部分代码会产生不同的结果: Calendar cd = Calendar.getInstance(); int hour
一个简单的问题,但我找不到它: HOUR_OF_DAY 的范围是 0 到 23,还是 1 到 24? 我想要一个随机的 HOUR_OF_DAY,我需要吗: int randomHour
在 Debug模式下,我看到我正在解析的值等于“2015-09-01 22:00”。当我创建日历时,我发现 HOUR_OF_DAY 等于 22。但是,interval 等于 10,而不是 22。错误在
问题:您认为这是 java.util.Calendar 中的错误吗? 本地 (PDT) 时区的日历对象被实例化并分配零(纪元开始)日期。在将日历的毫秒、秒和分钟设置为零后,该值将按照预期保持不变。然而
我写了一段代码从日历对象中获取小时的值,但它返回了错误的结果。 mpleDateFormat sf = new SimpleDateFormat("hh:mm"); try {
我有这段代码: Calendar cal = Calendar.getInstance(); cal.setTime(pDatum); cal.set(Calendar.HOUR_OF_DAY, In
这个问题已经有答案了: How to set time zone of a java.util.Date? (12 个回答) 已关闭5 年前。 JVM 版本为 1.7。时区为 GMT+3,偏移 180
我试图在 jsinner 控件中以这种格式 hh:mm 显示时间 但我得到的是 12 小时而不是 24 小时 这是我的代码 我哪里错了 Date date = new Date(); SpinnerD
下面的java代码: Calendar calend = Calendar.getInstance(TimeZone .getTimeZone("Pacific/Fak
将数据从文本文件导入到 CSV 文件输出时出现以下错误。我检查了日期,没有发现日期有任何错误。谁能解释一下什么是 HOUR_OF_DAY 错误。 工作;- tFileInputdelimited --
我需要在当前时间上添加两个小时并以 24 小时格式表示。这是我的代码 public class Tester { @Test public void test() { //for ex
我正在尝试将我的时间(以分钟为单位)转换为 HH:MM。例如 418 分钟 = 6:58。我正在使用以下代码: long milli = PriemCas*60000; Calendar cale
我有一个关于 java 时区的棘手问题(至少对我来说)。我将从一个按预期工作的示例开始: TimeZone tz = TimeZone.getDefault(); SimpleDateFormat s
我在 cal.set(Calendar.HOUR_OF_DAY, 0); 方面遇到问题。如果我使用第一个 DST 天,此方法将返回前一天 23:00:00,而不是当天 00:00:00。 我的时区是巴
我是 Java 新手。如何定义 DAY_OF_WEEK HOUR_OF_DAY 类型的enum。我想使用日历对象。我不会创建自己的枚举。我想要相同的: public DAY_OF_WEEK fro
我正在使用以下代码尝试获取 unix 时间戳的 HOUR_OF_DAY (0-23),并将其转换为毫秒。时间戳“1296442971”转换为 Sun Jan 30 2011 22:02:51 GMT-
Calendar.HOUR 和 Calendar.HOUR_OF_DAY 有什么区别?何时使用 Calendar.HOUR 和 Calendar.HOUR_OF_DAY ?有时我很困惑 Calenda
我的代码 Calendar calendar = Calendar.getInstance(); thisHour = calendar.get(Calendar.HOUR_OF_DA
我正在阅读 date4j homepage在谈论 Java 的 Calendar 类的问题时,它指出了以下内容: Calendar has two items referring to the hou
当我解析 2014-10-06 12:00:00 时,我很惊讶为什么日历 HOUR_OF_DAY 在下面的示例中打印 0。 我明白如果 HOUR 打印 0,但 HOUR_OF_DAY 不应该打印 12
我是一名优秀的程序员,十分优秀!