Decalaje UTC

Lucrul cu date și ore în Python

Max Shron

Data Scientist and Author

Lucrul cu date și ore în Python

Lucrul cu date și ore în Python

Lucrul cu date și ore în Python

Lucrul cu date și ore în Python

Lucrul cu date și ore în Python

Lucrul cu date și ore în Python

UTC

# Import relevant classes
from datetime import datetime, timedelta, timezone
Lucrul cu date și ore în Python

UTC

# Import relevant classes
from datetime import datetime, timedelta, timezone

# US Eastern Standard time zone
ET = timezone(timedelta(hours=-5))

# Timezone-aware datetime dt = datetime(2017, 12, 30, 15, 9, 3, tzinfo = ET)
print(dt)
2017-12-30 15:09:03-05:00
Lucrul cu date și ore în Python

UTC

# India Standard time zone
IST = timezone(timedelta(hours=5, minutes=30))

# Convert to IST print(dt.astimezone(IST))
2017-12-31 01:39:03+05:30
Lucrul cu date și ore în Python

Ajustarea fusului orar vs. modificarea tzinfo

print(dt)
2017-12-30 15:09:03-05:00

print(dt.replace(tzinfo=timezone.utc))
2017-12-30 15:09:03+00:00
# Change original to match UTC
print(dt.astimezone(timezone.utc))
2017-12-30 20:09:03+00:00
Lucrul cu date și ore în Python

Decalaje UTC

Lucrul cu date și ore în Python

Preparing Video For Download...