#encoding=utf-8
import time
# 返回时间戳
print time.time()
# 延迟运行单位为s,如下为延迟3s
time.sleep(3)
# 转换时间戳为时间元组(时间对象),自1970+second,其second为秒数
print time.gmtime(4)
# 转换时间戳为本地对象
print time.localtime()
# 将时间戳转换为字符串
print time.asctime(time.localtime())
# 将时间戳转换为字符串
print time.ctime(5)
# 将本地时间转换为时间戳
t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)
print time.mktime(t)
# 将时间对象转换为规范性字符串(常用),格式如下
'''
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale's equivalent of either AM or PM.
'''
print time.strftime('%Y-%m-%d %H-%M-%S',t)
# 将时间字符串根据指定的格式化符转换成数组形式的时间
struct_time = time.strptime("30 Nov 00", "%d %b %y")
print struct_time