date & time
formats
ISO9075 YYYY-MM-DD hh:mm:ss
RFC3339 YYYY-MM-DDThh:mm:ssZ
timezone
postgreSQL
As a general rule, prefer to store datetime as UTC.
Even when a TIME ZONE is set, postgres stores it as UTC. Conversion only occurs at insert/select.
A column TIMESTAMP WITH TIME ZONE
is not equivalent to ̀TIMESTAMP WITHOUT TIME ZONE`: returned data will be offset-aware in first case, offset-naive in second.
python
datetime.timezone
is ok for simple offset but does not handle DST switches.
For this use zoneinfo
(also in stdlib):
import datetime as dt
from zoneinfo import ZoneInfo
tz_paris = ZoneInfo('Europe/Paris')
dt.datetime.now(tz_paris)
Warning
Prefer ZoneInfo (stdlib) over pytz (kind of deprecated)
javascript
prefered lib: date-fns (or date-fns-tz)