0

我对 java.sql.Time 对象如何计算时间有点困惑。

我试图在每天的某个时间设置一个计时器。但是,在计算时间时,要设置警报,我似乎将警报提前一小时设置。

不过,这开始发生在 494 天前(当前日期是 2013 年 7 月 17 日)。如果您返回更远的地方(例如 1000 天前),也会发生这种情况,我猜它每隔几百天就会循环 +1 小时和 +0 小时。

我可以从我的输入时间中减去一个小时,但我想了解为什么会这样。

private static long oneDayInMill = timeToMill(24, 0); 
private static long reminderTime = timeToMill(13 + 6, 25); //military time; it starts at 18, not 0 for some reason
private static long currentTimeInMill = System.currentTimeMillis() % oneDayInMill;
private static long currentDayInMill = System.currentTimeMillis() - currentTimeInMill;

    System.out.println(new Time(currentDayInMill - (oneDayInMill*495)+ reminderTime).toString());
// This displays as 13:25:00 (as  I expect)
    System.out.println(new Time(currentDayInMill - (oneDayInMill*494)+ reminderTime).toString());
// This displays as 14:25:00 (not as I would expect)

public static long timeToMill(int hr, int min){
        //out of bounds
        return (hr*60*60*1000 + min*60*1000);
    }

我认为我的计算机使用的时区是 CST(这是我输出 Date java.util.Date 对象时的输出)

对不起,如果我的问题有点混乱

4

1 回答 1

0

rgettman 和 Dave Bartlett 是对的。如果我在 495 天前打印出日期对象,我会收到

Sat Mar 10 18:00:00 CST 2012

如果我在 494 天前打印出日期对象,我会收到:

Sun Mar 11 19:00:00 CDT 2012
于 2013-07-18T14:21:11.373 回答