Datetime Time-saving Facts

·

2 min read

Quick pointers on the formats and standards to be aware when working with date and time data.

Epoch Time (Unix Time/Posix Time)

  • The number of seconds elapsed since 01 Jan 1970 midnight

  • Integer value without timezone. i.e., it represents UTC timestamp.

  • Always increasing with every passing second.

  • Typically, number of seconds. Also used are number of milliseconds and nanoseconds for greater precision.

  • Most scalable/robust way of representing datetime in DB.

UTC (Coordinated Universal Time)

  • Current global standard time. Historically, known as GMT (Greenwich Mean Time).

  • De facto for International communication, navigation, scientific research, and commerce.

  • Clock time at reference time line (longitude passing Greewich city, UK).

  • Has no timezone (since it's 0th timezone meridian).

  • Every other world clock is derived from UTC time, by adding/subtracting timezone offsets (+/- hh:mm).

  • UTC offset for Indian Standard Time (IST) is +05:30.

  • Z character in ISO datetime format indicates UTC, i.e., without timezone.

  • DB stores datetime in UTC.

  • Always, choose UTC in business logic/service layers. Timezone conversion should be handled at presentation layer.

ISO 8601 Standard

  • International standard for communicating/representing Date and Time related data.

  • Greatest temporal term (typically a year) is placed at the left, followed by each successively lesser term.

  • YYYY-MM-DDThh:mm:ss.sssZ, where optional timezone offset Z for UTC, or +/-hh:mm for others.

  • String format of datetime, if required (in DB or JSON), should ideally be in ISO.

Miscellaneous

  • Mean Solar Time - Time calculation based on the position of Sun in the sky, where "day" is the fundamental unit of solar time.

  • Leap Second - "one second" adjustment that's occasionally added to UTC time to accommodate for difference between precise time and observed Solar Time.

  • Atomic Clock - Most accurate clock, where time is measured by monitoring resonant frequency of atoms.

  • Daylight Saving Time (DST) - The practice of advancing clocks to make better use of the longer daylight available during summer so that darkness falls at a later clock time.

Resources