import time
int(time.mktime(time.strptime('2013-10-10 23:40:00', "%Y-%m-%d %H:%M:%S")))
# 1381419600
import time
time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(1557673200))
# '2019-05-12 23:00:00'
from datetime import datetime, timedelta
datetime.now() + timedelta(days = 1)
timedelta
不支持月的单位,需要用dateutil
from datetime import datetime
from dateutil.relativedelta import relativedelta
datetime.now() + relativedelta(months = 1)
import datetime
datetime.datetime.now()
# datetime.datetime(2019, 7, 8, 21, 14, 37, 897386)
import datetime
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
import datetime
datetime.datetime.fromtimestamp(1538271871.226226).strftime('%Y-%m-%d %H:%M:%S.%f')
# '2018-09-30 09:44:31.226226'
import datetime
datetime.datetime.strptime('2018-09-30 09:44:31.226226','%Y-%m-%d %H:%M:%S.%f')
# datetime.datetime(2018, 9, 30, 9, 44, 31, 226226)
from datetime import datetime
time_gap = datetime.now() - datetime.strptime('2017-8-1 18:20:20', '%Y-%m-%d %H:%M:%S')
str(time_gap)
datetime.fromtimestamp(now_time)