Python

Python

Python time calendar

197011

Python time time.time(), :

(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- import time # time ticks = time.time() print ":", ticks

: 1459994552.51

1970UNIXWindows2038



Python9:

042008
11 12
2131
3023
4059
5061 (6061 )
606 (0)
71366 ()
8-1, 0, 1, -1

struct_time

0tm_year2008
1tm_mon1 12
2tm_mday1 31
3tm_hour0 23
4tm_min0 59
5tm_sec0 61 (6061 )
6tm_wday06 (0)
7tm_yday1 366()
8tm_isdst-1, 0, 1, -1


localtime

(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- import time localtime = time.localtime(time.time()) print " :", localtime

 : time.struct_time(tm_year=2016, tm_mon=4, tm_mday=7, tm_hour=10, tm_min=3, tm_sec=27, tm_wday=3, tm_yday=98, tm_isdst=0)


asctime():

(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- import time localtime = time.asctime( time.localtime(time.time()) ) print " :", localtime

 : Thu Apr  7 10:05:21 2016

time strftime

time.strftime(format[, t])

(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- import time # 2016-03-20 11:45:39 print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # Sat Mar 28 22:24:24 2016 print time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()) # a = "Sat Mar 28 22:24:24 2016" print time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y"))

2016-04-07 10:25:09
Thu Apr 07 10:25:09 2016
1459175064.0

python

  • %y 00-99
  • %Y 000-9999
  • %m 01-12
  • %d 0-31
  • %H 240-23
  • %I 1201-12
  • %M 00-59
  • %S 00-59
  • %a
  • %A
  • %b
  • %B
  • %c
  • %j 001-366
  • %p A.M.P.M.
  • %U 00-53
  • %w 0-6
  • %W 00-53
  • %x
  • %X
  • %Z
  • %% %

Calendar

(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- import calendar cal = calendar.month(2016, 1) print "20161:" print cal

20161:
    January 2016
Mo Tu We Th Fr Sa Su
             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 31


Time

Time

1time.altzone
2time.asctime([tupletime])
"Tue Dec 11 18:07:14 2008"2008121118071424
3time.clock( )
CPUtime.time()
4time.ctime([secs])
asctime(localtime(secs))asctime()
5time.gmtime([secs])
1970tt.tm_isdst0
6time.localtime([secs])
1970tt.tm_isdst01
7time.mktime(tupletime)
1970
8time.sleep(secs)
secs
9time.strftime(fmt[,tupletime])
fmt
10time.strptime(str,fmt='%a %b %d %H:%M:%S %Y')
fmt
11time.time( )
1970
12time.tzset()
TZ

Time2

1time.timezone
time.timezone >0<=0
2time.tzname
time.tzname


Calendar

calendar.setfirstweekday()

1calendar.calendar(year,w=2,l=1,c=6)
year3c w21* W+18+2* Cl
2calendar.firstweekday( )
calendar 0
3calendar.isleap(year)

True False

>>> import calendar
>>> print(calendar.isleap(2000))
True
>>> print(calendar.isleap(1900))
False
4calendar.leapdays(y1,y2)
Y1Y2
5calendar.month(year,month,w=2,l=1)
yearmonthw7* w+6l
6calendar.monthcalendar(year,month)
Yearmonth0;1
7calendar.monthrange(year,month)
06;112
8calendar.prcal(year,w=2,l=1,c=6)
print calendar.calendar(year,w=2,l=1,c=6)
9calendar.prmonth(year,month,w=2,l=1)
print calendar.month(year,month,w=2,l=1)
10calendar.setfirstweekday(weekday)
06
11calendar.timegm(tupletime)
time.gmtime1970
12calendar.weekday(year,month,day)
06 1 1212


Python