python date time

//test.py

import time

ticks = time.time()
print ticks
localtime = time.localtime(time.time())
print localtime
print time.asctime(localtime)

print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
t = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime())
print t
print time.mktime(time.strptime(t, '%a %b %d %H:%M:%S %Y'))
print 'altzone:',time.altzone
t1 = time.clock()
print 't1', t1
#time.sleep(1)
t2 = time.clock()
print 't2', t2
print 'ctime',time.ctime()
print 'gmtime', time.gmtime()
print 'localtime', time.localtime()
print 'timezone',time.timezone
print time.tzname


import calendar

cal = calendar.month(2017, 11)
print cal
print calendar.calendar(2017, w=2,l=1,c=6)
print calendar.firstweekday()
print calendar.isleap(2017)
print calendar.leapdays(2017, 2022)
print calendar.month(2017,11, w=2,l=1)
print calendar.monthcalendar(2017, 11)
print calendar.monthrange(2017, 11)
calendar.setfirstweekday(6)
print 'firstweekday',calendar.firstweekday()
print calendar.timegm(time.localtime())
print calendar.weekday(2017,11,6)

//result

# python test.py

1509959417.55
time.struct_time(tm_year=2017, tm_mon=11, tm_mday=6, tm_hour=1, tm_min=10, tm_sec=17, tm_wday=0, tm_yday=310, tm_isdst=0)
Mon Nov 6 01:10:17 2017
2017-11-06 01:10:17
Mon Nov 06 01:10:17 2017
1509959417.0
altzone: 25200
t1 0.010813
t2 0.010816
ctime Mon Nov 6 01:10:17 2017
gmtime time.struct_time(tm_year=2017, tm_mon=11, tm_mday=6, tm_hour=9, tm_min=10, tm_sec=17, tm_wday=0, tm_yday=310, tm_isdst=0)
localtime time.struct_time(tm_year=2017, tm_mon=11, tm_mday=6, tm_hour=1, tm_min=10, tm_sec=17, tm_wday=0, tm_yday=310, tm_isdst=0)
timezone 28800
('PST', 'PDT')

0
False
1

[[0, 0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26], [27, 28, 29, 30, 0, 0, 0]]
(2, 30)
firstweekday 6
1509930617
0

原文地址:https://www.cnblogs.com/woodzcl/p/7794155.html