Python日付変換の一般的な方法(datetime、time)

3714 ワード

x = datetime(2012, 11, 19, 23, 30, 59)
print(x)

x = datetime.strptime('2012-11-19', '%Y-%m-%d')
print(x)
# datetime -> ts
time_time = time.mktime(datetime.today().timetuple())
print(time_time)

# ts -> string
time.strftime('%Y-%m-%d', time.localtime(time_time))
# datetime -> string
now_str = datetime.today().strftime('%Y-%m-%d')
print(now_str)

x = datetime.strptime(now_str, '%Y-%m-%d')
print(x)
# date -> datetime
x = date(2012, 11, 19)
print(x)