我正在尝试获得正确的偏移量,以便使用它进行一些计算,但遇到了问题。当我知道此时偏移量应该是5时,我总是得到零。如果有人能帮助查明问题,那将大有帮助。
DateTimeZone dateTz = DateTimeZone.forID('America/Chicago')
DateTime now = new DateTime(dateTz)
DateTimeZone tz = DateTimeZone.forID("UTC");
long offsetInMilliseconds = tz.getOffset(now.getMillis())
当变量offsetInMilliseconds应该是正确的偏移量时,它将始终为0。
好吧,看起来我需要使用getOffsetFromLocal,而不是getOffset,这个谜已经解开了。