獲取本地時間
import time local_time = time.asctime( time.localtime(time.time()) ) print "Local current time :", local_time
執行結果:
[gang@teach gyyx]$ python getTime.py Local current time : Mon Sep 22 11:19:38 2014
2. 獲取日曆視圖
#!/usr/bin/python import time, calendar cal = calendar.month(int(time.strftime("%Y")), int(time.strftime("%m"))) print "Here is the calendar:" print cal;
運行結果:
[gang@teach gyyx]$ python getCal.py Here is the calendar: September 2014 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