Date & Time

OK, you are thinking about date & time handling in your application. You’ve already known some obvious things such as:

  • there are 86400 seconds in a day
  • there are 365 days in an ordinary year
  • there are 366 days in a leap year
  • there are 719528 days between Jan 1, 0 and Jan 1, 1970.

But do you remember about the following?:

  • your application must somehow handle the century changes 🙂
  • by the Gregorian rule, a year YYYY is a leap year if either of the following rules is valid: YYYY is divisible by 4, but not by 100; or YYYY is divisible by 400 ( 1996 is a leap year, 1900 is not, but 2000 is).
  • leap seconds
  • timezone on server and timezone on client machine can be different 🙂 . It is wise to save data with UTC time on server.
  • one more about timezones: there are lot of countries using daylight saving time or summer time. You need remember about this if you need to calculate timezone by the difference between some local time and UTC. For example Central European Time is UTC+1 and Central European Summer Time is UTC+2. Also changing to DST is different for Europe and USA.

Some formulas for Europe:
summer time
begins at: Sunday (31 − (5*YYYY ÷ 4 + 4) mod 7) March at 01:00 GMT
summer time
ends at: Sunday (31 − (5*YYYY ÷ 4 + 1) mod 7) October at 01:00 GMT
(valid till 2099, see DST)
Hmm…. What else do we need to know about the time?