涉及对象
1.datetime
import datetime
x=datetime.datetime.now() #2018-01-10 16:45:25.474000
x=datetime.datetime.now().date() #2018-01-10
x=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") #'2018-01-10 10:10:12' 只有这个输出的是字符串格式,其他的都是日期格式
x=datetime.datetime.today() #2018-01-10 11:18:52.079000
注意:
>>> datetime.datetime.now()
datetime.datetime(2018, 1, 12, 11, 24, 54, 7000)
>>> print datetime.datetime.now()
2018-01-12 11:25:06.615000
>>> print datetime.datetime.combine(datetime.date.today(),datetime.time.min)
2018-01-12 00:00:00
>>> print datetime.datetime.combine(datetime.date.today(),datetime.time.max)
2018-01-12 23:59:59.999999
>>> print (datetime.datetime(2018,1,1,1,1,1)-datetime.datetime.now()).total_seconds()
-988227.107
x=datetime.date.today() #2018-01-10
x=datetime.date.today() + datetime.timedelta(days=1) #2018-01-11
2.time
import time
time.time() #1421075455.568243
time.loacaltime() #time.struct_time(tm_year=2018, tm_mon=1, tm_mday=10, tm_hour=16, tm_min=55, tm_sec=26, tm_wday=2, tm_yday=10, tm_isdst=0)
3.calendar