Reputation: 11282
Given UTC date and time as year
, month
, day
, hour
, minute
, second
, I was wondering about a pseudo-code algorithm to calculate the corresponding Unix epoch timestamp.
There are 60 seconds in a minute, 60 minutes in an hour, 24 hours in a day. So we can just use 60 × 60 × 24 = 86400 seconds per day and count the days backwards until 1970-01-01T00:00:00Z, right? Months have different numbers of days, though. So it's probably better to skip that and use 365 days per year. But then, there's leap years... and leap seconds... and more?
Does that suddenly make the algorithm as complex as dealing with timezones or is it still fairly easy to describe?
Upvotes: 1
Views: 2481