By using Java util. Date may have underflow errors

This Code:

package test;

import java.util.Date;

public class DateUnderflow {

    public static void main(String[] args) {
        Long timestamp = -8120649749785140250L;
        System.out.println(new Date(timestamp));
    }
}

The following outputs are generated:

"Sat Aug 03 10:00:59 CET 257325894"

How? Underflow without exception?

Doc said that the date parameter of the date (long date) is the number of milliseconds since the era, so I was a little surprised to find that I was far from here

My settings:

>Linux 17.1 > eclipse Luna service release 1a (4.4.1) > java7-openjdk-amd64

Solution

RTFM( manual)

Do not exceed 8099 milliseconds

In addition, I'm most likely to save time in the following ways: if you process time in Java, use joda time library:

http://www.joda.org/joda-time/

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>