# Python2
import datetime, time
base_data = "Feb 27 00:51:29 2021 GMT"
date_time = time.strptime(base_data, "%b %d %H:%M:%S %Y GMT")
unix_time = int(time.mktime(date_time))
gen_based = datetime.datetime.fromtimestamp(unix_time).strftime("%b %d %H:%M:%S %Y GMT")
# >>> print base_data
# Feb 27 00:51:29 2021 GMT
# >>> print date_time
# time.struct_time(tm_year=2021, tm_mon=2, tm_mday=27, tm_hour=0, tm_min=51, tm_sec=29, tm_wday=5, tm_yday=58, tm_isdst=-1)
# >>> print unix_time
# 1614354689
# >>> print gen_based
# Feb 27 00:51:29 2021 GMT
# >>> base_data == gen_based
# True
Recommended Posts