2

I've been researching on how different operating systems represent time, as well as how to convert between them. I've read several pages that all describe a similar method for converting between FILETIME and Unix time, most notably this post. The logic behind how this works is pretty simple and plainly states that there's been 11644473600 seconds from January 1st, 1601 to January 1st 1970.

My question is: Why is the constant 11644473600 and not 11644732800?

When I divide out 11,644,473,600 seconds, that equals 134,774 days. That would include 92 leap years and comes out to ~368.99 years. Every time I run the numbers myself, the number I come out to for 369 years (which would contain 92 leap years) ends up being 11,644,732,800 seconds (134,777 days).

Am I just doing some bits of math wrong or is there some other bits of information that I haven't read or learned about how this conversion works?

EDIT: As pointed out by Vladimir Posvistelik, my issue was that I wasn't calculating leap years correctly. The years 1700, 1800, and 1900 are NOT leap years. This explains my number being off by three days.

Azrael
  • 87
  • 5
  • 1
    This looks like a good question, but it doesn't appear to be a [programming question](https://stackoverflow.com/help/on-topic). You might want to ask this on one of the linux sites instead, e.g. Unix & Linux SE or Super User or Server Fault – Brian61354270 Aug 07 '23 at 21:30
  • 1
    @Brian61354270 I'm not fully agree with you: dates manipulation is a classic programming problem (at some point). As a result, we may find a lot of similar questions on SO. – Vladimir Posvistelik Aug 07 '23 at 21:44
  • I agree, understanding some magic constant used in programming format conversions seems fine as a SO question. I had a similar conversion issue with one of Microsoft's date formats earlier this year. – Dave S Aug 07 '23 at 21:56

1 Answers1

1

I think they came from the fact, that not all years divisible by 4 are leap. As said on Wikipedia:

This extra leap day occurs in each year that is an integer multiple of 4 (except for years evenly divisible by 100, but not by 400)

Vladimir Posvistelik
  • 3,843
  • 24
  • 28
  • 1
    After reading the wiki page linked in this answer, this was the important piece of the puzzle I was missing. In school they simply said every four years was a leap year. Thank you for clearing that up. – Azrael Aug 07 '23 at 22:56
  • 1
    @Azrael in addition I can recommend the following aggregation of "date-time false assumptions" - FalsehoodsAboutTime.com (which is a shortcut to the original blog post https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time) – Vladimir Posvistelik Aug 08 '23 at 15:27