In [1]:
import datetime
import pytz
In [2]:
jst = pytz.timezone('Asia/Tokyo')
In [3]:
print(jst)
In [4]:
eastern = pytz.timezone('US/Eastern')
In [5]:
print(eastern)
In [6]:
print(type(jst))
In [7]:
print(issubclass(type(jst), datetime.tzinfo))
In [8]:
dt_aware = datetime.datetime(2018, 12, 31, 5, 0, 30, 1000,
tzinfo=datetime.timezone.utc)
In [9]:
print(dt_aware)
In [10]:
print(dt_aware.astimezone(jst))
In [11]:
print(dt_aware.astimezone(eastern))
In [12]:
print(dt_aware.replace(tzinfo=jst))
In [13]:
print(dt_aware.replace(tzinfo=eastern))
In [14]:
print(jst.localize(dt_aware.replace(tzinfo=None)))
In [15]:
print(eastern.localize(dt_aware.replace(tzinfo=None)))
In [16]:
dt_naive = datetime.datetime(2018, 12, 31, 5, 0, 30, 1000)
In [17]:
print(dt_naive)
In [18]:
print(dt_naive.replace(tzinfo=jst))
In [19]:
print(dt_naive.replace(tzinfo=eastern))
In [20]:
print(jst.localize(dt_naive))
In [21]:
print(eastern.localize(dt_naive))
In [22]:
print(datetime.datetime(2018, 12, 31, 5, 0, 30, 1000,
tzinfo=jst))
In [23]:
print(jst.localize(datetime.datetime(2018, 12, 31, 5, 0, 30, 1000)))
In [24]:
print(datetime.datetime.now(jst))
In [25]:
dt_dst = datetime.datetime(2018, 3, 11, 2, 0, 0, 0)
In [26]:
print(eastern.localize(dt_dst))
In [27]:
print(eastern.normalize(eastern.localize(dt_dst)))