CKTIS / Python
Modul datetime
Pruža datume, vrijeme, vremenske oznake i trajanja.
Verzija: Python 3.14; repository image, production runtime not attested
Sintaksa
datetime.datetime.fromisoformat(text)Pruža datume, vrijeme, vremenske oznake i trajanja.
Datetime s pomakom prema UTC-u određuje trenutak, a naivni datetime sam ga ne određuje. Pretvorba u UTC može promijeniti kalendarski dan.
Oduzimanje naivnog datetime od onoga s vremenskom zonom izaziva TypeError.
Primjeri
import datetime
local = datetime.datetime.fromisoformat("2026-01-02T00:30:00+02:00")
utc = local.astimezone(datetime.UTC)
print(utc.isoformat(), local == utc)
try:
local - local.replace(tzinfo=None)
except TypeError:
print("mixed awareness")
Rezultat
2026-01-01T22:30:00+00:00 True mixed awareness
Oduzimanje naivnog datetime od onoga s vremenskom zonom izaziva TypeError.