datetime

import time
from datetime import datetime

print(time.ctime(),type(time.ctime()))
print(time.gmtime(),type(time.gmtime()))
print(datetime.datetime.now(),type(datetime.datetime.now()))
print(datetime.datetime(2019,9,19)+datetime.timedelta(1))
print(time.strftime('%Y/%m/%d %H:%M:%S', time.localtime()))
print(time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime()))
dt = datetime.timestamp(datetime.now())
print(dt, type(dt))
df = datetime.fromtimestamp(dt)
print(df, type(df))

print(datetime.weekday(datetime.today()))
print(datetime.utcnow())
ds = datetime.strptime('2019-09-26 18:17:36', '%Y-%m-%d %H:%M:%S')
print(ds, type(ds))
dtf=datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
print(dtf,type(dtf))


def get_other_time(day,format='%Y%m%d%H%M%S'):
    #这个函数是用来获取N天前的时间,或者N天后的时间
    #day如果传入负数,那么就是几天前的。传入正数,就是几天后的
    import datetime
    res = datetime.datetime.now()+datetime.timedelta(day)#取几天后的
    res_time = res.strftime(format)#格式化时间
    return res_time

你可能感兴趣的:(datetime)