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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
""" Author : Zeuxis Lo (傻心 - 窮等人家) Pub-Date: 4/7/2009 13:07 """
timeZone = 8
import time
print "Content-type: text/html" print
""" 實現 Perl 的類似寫法 """
year, month, day, hour, min, sec, wday, ydate, isdst = time.localtime()
if month < 10: month = "0%s" % month if day < 10: day = "0%s" % day if hour < 10: hour = "0%s" % hour if min < 10: min = "0%s" % min if sec < 10: sec = "0%s" % sec
print "%s-%s-%s %s:%s:%s <br />" % (year, month, day, hour, min, sec)
""" 簡化寫法 -------- 相關的參數參考: http://docs.python.org/library/time.html#time.struct_time """
print time.strftime("%Y-%m-%d %H:%M:%S <br />", time.localtime())
print time.strftime("%Y-%m-%d %H:%M:%S <br />", time.gmtime(time.time()+timeZone*3600))
""" 嘗試實現類似於 PHP 的秒和時間互轉 -------- 相關的參考資料: http://bytes.com/groups/python/160549-time-mktime-problem http://blog.csdn.net/JGood/archive/2009/06/23/4292912.aspx """
print time.mktime(time.strptime('2009-07-04 13:53:00', '%Y-%m-%d %H:%M:%S')) print "<br />"
print time.strftime("%Y-%m-%d %H:%M:%S <br />", time.localtime(1246686780.0)) print time.strftime("%Y-%m-%d %H:%M:%S <br />", time.gmtime(1246686780.0+timeZone*3600))
|