Java – why are different long values converted to the same date / time?

public static void getTime() {
public static void getTime() {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Time t1 = new Time(Long.parseLong("1369213412435"));
    Time t2 = new Time(Long.parseLong("1369213412245"));
    System.out.println(sdf.format(t1));
    System.out.println(sdf.format(t2));
}

Why print the code above,

2013-05-22 17:03:32
2013-05-22 17:03:32

Solution

The difference between these two dates is only milliseconds (435 or 245). You can ignore these dates in the format

use:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");

See different values

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
分享
二维码
< <上一篇
下一篇>>