# Dates and how to use it

Javascript has only Datetime object which we use to store both date and datetime.

# Date

Date represents single day, since timezone doesn't make much sense without time, we're using datetime with zeroed-out hours, minutes, seconds, and timezone (this means it's always in UTC). We're using getUTCDate, getUTCFullYear and getUTCMonth to access it's value!

In ISO8601 (29. 6. 2020) is formated as 2020-06-29T00:00:00Z

# DateTime

Datetime represents single point in history. How we'll represent it back to user depends on project:

  • to display datetime in user's timezone, we're using non-utc datetime methods (getDate, getFullYear..)
  • to display time in specific timezone (Europe/Prague), we're using Intl.DateTimeFormat

In ISO8601 can be formatted using any timezone (29. 6. 2020 17h 15 min 10s in Prague) 2020-06-29T15:15:10Z,2020-06-29T17:15:10+0200

# Postgresql

Posgresql can't store timezone in db. Workaround is converting all datetimes always to utc and storing it in db without timezone, when retrieved utc timezone is added to it when creating backend datetime object.

Last Updated: 6/29/2020, 3:29:59 PM