Python模块之time

#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

转载自:http://www.cnblogs.com/cmnz/p/9099564.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值