Reputation: 2070
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 does the above code prints,
2013-05-22 17:03:32
2013-05-22 17:03:32
Upvotes: 3
Views: 329
Reputation: 811
Apart from the millisecond parts there are certain cases where two long values can provide same date.
i.e. below two long values have same millisecond and are different
If you use dd-MM-yyyy hh:mm:ss SSS then it will give you the same result.
Catch here is hh (12 hr format) vs HH (24 hr format).
Using this will give the accurate result dd-MM-yyyy HH:mm:ss SSS
Upvotes: 0
Reputation: 12754
The two dates are differed by milliseconds i.e. 435
and 245
.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
This will do.
Upvotes: 4
Reputation: 13713
Use :
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss:SSS");
and you will see the difference in the milliseconds part.
Upvotes: 3
Reputation: 19304
The two dates differ only by milliseconds (435 or 245), which you ignore in your format.
Use:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
to see the different values.
Upvotes: 10