下面实例可以测试 time.asctime([t]) 的几种使用方法:
# -*- coding:utf-8 -*-
import time
#test1: 不加参数,默认就是time.localtime()返回的时间结构元组
print "test1: print time.asctime():",time.asctime()
#test2: time.loaltime() 本地时间
t1 = time.localtime()
print "test2: t1(localtime):",t1
print "test2: time.asctime(t1):",time.asctime(t1)
#test3: time.gmtime() 格林威治标准时间
t2 = time.gmtime()
print "test3: t2(gmtime):",t2
print "test3: time.asctime(t2):",time.asctime(t2)
#test4: 按time_struct,人工指定时间结构元组
t3 = [2018,5,27,1,5,27,6,147,-1]
print "test4: t3:",t3
print "test4: time.asctime(t3):",time.asctime(t3)
返回结果:
test1: print time.asctime(): Sun May 27 01:14:26 2018
test2: t1(localtime): time.struct_time(tm_year=2018, tm_mon=5, tm_mday=27, tm_hour=1, tm_min=14, tm_sec=26, tm_wday=6, tm_yday=147, tm_isdst=0)
test2: time.asctime(t1): Sun May 27 01:14:26 2018
test3: t2(gmtime): time.struct_time(tm_year=2018, tm_mon=5, tm_mday=26, tm_hour=23, tm_min=14, tm_sec=26, tm_wday=5, tm_yday=146, tm_isdst=0)
test3: time.asctime(t2): Sat May 26 23:14:26 2018
test4: t3: [2018, 5, 27, 1, 5, 27, 6, 147, -1]
test4: time.asctime(t3): Sun May 27 01:05:27 2018
小兔爱囧囧
小兔爱囧囧
dia***dtu@163.com3年前 (2018-05-27)