Dec. 6th, 2016

post

Dec. 6th, 2016 08:45 pm
sergey_cheban: (Аракчеев)
Оригинал взят у [livejournal.com profile] juan_gandhi в post
http://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result

"Why is subtracting these two times (in 1927) giving a strange result?"

public static void main(String[] args) throws ParseException {
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
    String str3 = "1927-12-31 23:54:07";  
    String str4 = "1927-12-31 23:54:08";  
    Date sDt3 = sf.parse(str3);  
    Date sDt4 = sf.parse(str4);  
    long ld3 = sDt3.getTime() /1000;  
    long ld4 = sDt4.getTime() /1000;
    System.out.println(ld4-ld3);
}


The output is 353...

Answer:

"at midnight at the end of 1927, the clocks went back 5 minutes and 52 seconds. So "1927-12-31 23:54:08" actually happened twice, and it looks like Java is parsing it as the later possible instant for that local date/time - hence the difference."

Page generated Jul. 20th, 2025 10:09 pm
Powered by Dreamwidth Studios