post

Dec. 6th, 2016 08:45 pm
sergey_cheban: (Аракчеев)
[personal profile] 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."

Date: 2016-12-06 07:32 pm (UTC)
From: [identity profile] raffal.livejournal.com
Хмм.. Спасибо, интересно, завтра поиграюсь.

Date: 2016-12-07 08:46 am (UTC)
From: [identity profile] dmitrmax.livejournal.com
Люто. А почему бы тогда leap second не учитывать? )
Page generated Jul. 25th, 2025 12:05 pm
Powered by Dreamwidth Studios