Looking for a bit of inspiration here ... I'm working on a small MCU program, part of which is timekeeping. What I'm doing is feeding it the absolute time in seconds elapsed since Jan 1, year 1 at 0:00:00 and start counting from there. Easy enough.
I'm doing things that way because I'm interfacing the MCU to a vb.net program in my computer, and .NET has a function that does exactly that. The function is DateTime.Now.Ticks, which returns the number of microseconds elapsed from the aforementioned start date.
Anyway. What I'm trying to do is convert those seconds back into a date. And that's proved a little more challenging than I thought.
I'm aware of the Gregorian calendar leap year exception every 100 years but not 400 years. That is, there's a leap year every 4 years, except when the year in question is a multiple of 100, but not a multiple of 400. For instance, the year 2000 is a multiple of 400 and it was a leap year, but the year 1900 is a multiple of 100 and therefore was not a leap year.
Thing is, I'm pulling my hair here trying to turn said logic into a simple formula. For instance, right now the current absolute time in seconds is: 637,932,155,780. Converting into days is easy enough: 63,793,218,220/(60 x 60 x 24) = 738,347.43310 . But converting it into years is the tricky part. According to my reasoning, an average year lasts 365 + 1/4 - 1/100 + 1/400 = 365.2425 days. Therefore, the amount of days I mentioned above result in:
738,347.43310/365.2425 = 2,021.5266 ... which is not even close to today's date (2022, July the 12th)
What gives?
I'm doing things that way because I'm interfacing the MCU to a vb.net program in my computer, and .NET has a function that does exactly that. The function is DateTime.Now.Ticks, which returns the number of microseconds elapsed from the aforementioned start date.
Anyway. What I'm trying to do is convert those seconds back into a date. And that's proved a little more challenging than I thought.
I'm aware of the Gregorian calendar leap year exception every 100 years but not 400 years. That is, there's a leap year every 4 years, except when the year in question is a multiple of 100, but not a multiple of 400. For instance, the year 2000 is a multiple of 400 and it was a leap year, but the year 1900 is a multiple of 100 and therefore was not a leap year.
Thing is, I'm pulling my hair here trying to turn said logic into a simple formula. For instance, right now the current absolute time in seconds is: 637,932,155,780. Converting into days is easy enough: 63,793,218,220/(60 x 60 x 24) = 738,347.43310 . But converting it into years is the tricky part. According to my reasoning, an average year lasts 365 + 1/4 - 1/100 + 1/400 = 365.2425 days. Therefore, the amount of days I mentioned above result in:
738,347.43310/365.2425 = 2,021.5266 ... which is not even close to today's date (2022, July the 12th)
What gives?
Last edited: