时间的三种形式:
1. 时间戳: 以整型或者浮点型表示, 以秒为单位的时间间隔,时间基础值是从1970年1月1号0点 time.time()
2. 元组:这个元组有9个整型内容(year, month, day,hour,minutes,second,week,julia day, falg(1,-1,0))
3.格式化字符串:%Y 4位的年份 %m %d
import time
c=time.time()
print c
t=time.gmtime(c)
print t
b=time.localtime()
print b
f=time.mktime(b)
print f
d=time.asctime(b)
print d
g=time.ctime(c)
print g
h=time.strftime("%Y-%m-%d %H:%M:%S",b)
print h
k=time.strptime(h,"%Y-%m-%d %H:%M:%S")
print k
1542419970.49
time.struct_time(tm_year=2018, tm_mon=11, tm_mday=17, tm_hour=1, tm_min=59, tm_sec=30, tm_wday=5, tm_yday=321, tm_isdst=0)
time.struct_time(tm_year=2018, tm_mon=11, tm_mday=17, tm_hour=9, tm_min=59, tm_sec=30, tm_wday=5, tm_yday=321, tm_isdst=0)
1542419970.0
Sat Nov 17 09:59:30 2018
Sat Nov 17 09:59:30 2018
2018-11-17 09:59:30
time.struct_time(tm_year=2018, tm_mon=11, tm_mday=17, tm_hour=9, tm_min=59, tm_sec=30, tm_wday=5, tm_yday=321, tm_isdst=-1)
time.sleep(3)
time.clock() : 返回当前程序的cpu时间
datetime:
模块中的类:
datetime类: 同时有日期和时间
timedeltam,
tzinfo,
time,
date
import datetime
curtime = datetime.datetime.now()
print curtime
#get the specific time
a= datetime.datetime(2011,8,10,19)
print a
b=curtime.strftime("%Y-%m-%d %X")
print b
2018-11-17 10:22:39.101000
2011-08-10 19:00:00
2018-11-17 10:22:39
2655 days, 15:22:39.101000
Calendar 模块:
import calendar
print calendar.calendar(2018)
print calendar.month(2018,1)
print calendar.isleap(2018)