gpt4 book ai didi

java.util.SimpleTimezone 什么是 startMode 和 endMode?

转载 作者:行者123 更新时间:2023-11-30 07:44:56 26 4
gpt4 key购买 nike

我正在尝试 Java 的 SimpleTimeZone,我想了解当我创建新的 SimpleTimeZone 对象时它生成的值。首先,这是我的代码和输出

import java.util.*;

public class SimpleTimeZoneDemo {
public static void main( String args[] ){
// create simple time zone object
SimpleTimeZone stobj = new SimpleTimeZone(820,"GMT");

// checking initial value
System.out.println("Initial value: " + stobj);

// setting start rule
stobj.setStartRule( Calendar.MAY, 2, 3600000);

// checking the new value
System.out.println("Final value : " + stobj);
}

它生成的输出是

Initial value: java.util.SimpleTimeZone[id=GMT,offset=820,dstSavings=3600000,
useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,
startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=0,endMonth=0,endDay=0,
endDayOfWeek=0,endTime=0,endTimeMode=0]

Final value : java.util.SimpleTimeZone[id=GMT,offset=820,dstSavings=3600000,
useDaylight=false,startYear=0,startMode=1,startMonth=4,startDay=2,
startDayOfWeek=0,startTime=3600000,startTimeMode=0,endMode=0,
endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]

什么是startModeendMode?为什么startMode从0变成1?我正在尝试弄清楚它似乎与夏令时有关?

最佳答案

startModeendMode 是内部字段。您无法在公共(public) API 中访问它们。

但是,如果查看源代码,它们会被记录下来:

对于startMode:

Variables specifying the mode of the start rule. Takes the following values:

  • DOM_MODE: Exact day of week; e.g., March 1.
  • DOW_IN_MONTH_MODE: Day of week in month; e.g., last Sunday in March.
  • DOW_GE_DOM_MODE: Day of week after day of month; e.g., Sunday on or after March 15.
  • DOW_LE_DOM_MODE: Day of week before day of month; e.g., Sunday on or before March 15.

The setting of this field affects the interpretation of the startDay field.

If useDaylight is false, this value is ignored.

对于endMode:

Variables specifying the mode of the end rule. Takes the following values:

  • DOM_MODE: Exact day of week; e.g., March 1.
  • DOW_IN_MONTH_MODE: Day of week in month; e.g., last Sunday in March.
  • DOW_GE_DOM_MODE: Day of week after day of month; e.g., Sunday on or after March 15.
  • DOW_LE_DOM_MODE: Day of week before day of month; e.g., Sunday on or before March 15.

The setting of this field affects the interpretation of the endDay field.

If useDaylight is false, this value is ignored.

在您的代码中,第一种情况下 startMode 为 0,因为它未初始化,因此 int 采用其默认值。它更改为 1,因为您将开始规则设置为特定日期,因此模式变为 DOM_MODE = 1。请注意,endMode 保持为 0,因为未设置结束规则。

关于java.util.SimpleTimezone 什么是 startMode 和 endMode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34071811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com