简体   繁体   English

Date.getTime()给出2000年1月1日的时间

[英]Date.getTime() giving a time of 2000 1st Jan

I have observed this unusual behavior in a few laptops. 我已经在几台笔记本电脑中观察到这种异常行为。 I had some issue running in the application we developed. 我在开发的应用程序中运行时遇到一些问题。 On debugging it we found that new Date.getTime() is pointing to an old date . 在调试时,我们发现新的Date.getTime()指向旧的date。 After that we tried to run a small program on those machines. 之后,我们尝试在这些计算机上运行一个小程序。 The following is the code we used. 以下是我们使用的代码。

import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

public class Test {

    public static void main(String... args)  {
        System.out.println(new Date().getTime());
        ConcurrentHashMap chm = new ConcurrentHashMap();

        for (int i = 0; i < 100000; i++) {
            chm.put(i, new Date().getTime());

                if (Long.parseLong(String.valueOf(chm.get(i))) < 1332334082344l) {
                    System.out
                            .println(Long.parseLong(String.valueOf(chm.get(i))));
                }



        }

        System.out.println("dONE "+chm.size()+" "+chm.get(1000));
    }
}

The output is something like "946684800617" if a few case. 如果是少数情况,输出类似于“ 946684800617”。 When we saw the date it points to Jan 1st 2000 and some milliseconds. 当我们看到日期时,它指向2000年1月1日和几毫秒。 This is not happening in all the laptops. 这并非在所有笔记本电脑中都发生。

Wanted to know why this is happening so that we can work over it. 想知道为什么会这样,以便我们可以解决它。

PS : We are using windows 7 (pro),Lenovo ThinkPad L420 PS:我们正在使用Windows 7(专业版),联想ThinkPad L420

This doesn't answer your question a such but your code is so complex it could have unintended consequences. 这样并不能回答您的问题,但是您的代码是如此复杂,可能会产生意想不到的后果。 Can you try running this which does the same thing? 您可以尝试运行相同的功能吗?

public class Test {
    public static void main(String... args) {
        int length = 100000;
        System.out.println(System.currentTimeMillis());
        long[] times = new long[length];
        for (int i = 0; i < length; i++) {
            times[i] = System.currentTimeMillis();
            if (times[i] < 1332334082344L)
                System.out.println(times[i]);
        }
        System.out.println("Done " + times.length + " " + times[1000]);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM