首页 > 编程语言 > 详细

Python学习笔记07

时间:2015-08-11 11:54:39      阅读:213      评论:0      收藏:0      [点我收藏+]

?

时间:

tickets

时间元组

格式化的时间

日历

import time

tickets = time.time()

print tickets

print time.localtime() #本地时间元组

print time.gmtime() #UTC时间元组

print time.asctime(time.localtime())

?

import calendar

print calendar.month(2015,8)

?

技术分享

?

CPU时钟:clock

睡眠:sleep

创建时间:mktime

#clock & sleep

import time

def procedure():

time.sleep(0.5)

?

t0 = time.clock()

procedure()

print time.clock() - t0

#mktime

t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)

secs = time.mktime(t)

print "time.mktime(t) : %f" % secs

print time.localtime(secs)

?

datetime:类似C#的DateTime

import datetime

dt = datetime.datetime(2015,8,11,10,31,55)

print dt

print dt.hour

print dt.second

?

delta = datetime.timedelta(hours=5)

print dt + delta

print dt - delta

?

?

from datetime import datetime

format = "output-%Y-%m-%d-%H%M%S.txt"

str = "output-1997-12-23-030000.txt"

t = datetime.strptime(str, format)

?

from datetime import *

print datetime.now()

print date.today()

Python学习笔记07

原文:http://www.cnblogs.com/pengzhen/p/4720344.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!