#!/usr/bin/env python
#标准库time及datetime
import time
print(time.time())
print(time.timezone)#本地时间与世界时间差,秒为单位
print(time.sleep(1),123)#睡几秒
print(time.gmtime(1541844509))#没有参数为世界时间戳
print(time.localtime())#没有参数为本地时间戳
print(time.localtime().tm_yday)
#print(help(time))
print(time.mktime(time.localtime()))
#print(help(time.mktime))
print(time.strftime('%Y-%m-%d %H:%M:%S'))
print(time.strptime('2018-11-10 18:30:32','%Y-%m-%d %H:%M:%S'))
z = time.mktime(time.strptime('2018-11-10 18:30:32','%Y-%m-%d %H:%M:%S'))
print(z)
print(time.asctime())
print(time.ctime())
import datetime
print(datetime.datetime.now())
print(datetime.datetime.now()+datetime.timedelta(-3))#3天前的时间
print(datetime.datetime.now()+datetime.timedelta(hours=-3))#3小时前的时间
1541851708.6755588
-28800
None 123
time.struct_time(tm_year=2018, tm_mon=11, tm_mday=10, tm_hour=10, tm_min=8, tm_sec=29, tm_wday=5, tm_yday=314, tm_isdst=0)
time.struct_time(tm_year=2018, tm_mon=11, tm_mday=10, tm_hour=20, tm_min=8, tm_sec=29, tm_wday=5, tm_yday=314, tm_isdst=0)
314
1541851709.0
2018-11-10 20:08:29
time.struct_time(tm_year=2018, tm_mon=11, tm_mday=10, tm_hour=18, tm_min=30, tm_sec=32, tm_wday=5, tm_yday=314, tm_isdst=-1)
1541845832.0
Sat Nov 10 20:08:29 2018
Sat Nov 10 20:21:12 2018
2018-11-10 20:21:12.877268
2018-11-07 20:21:12.877268
2018-11-10 17:21:12.877268
参考链接:http://blog.51cto.com/egon09/1840425