码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习笔记07

时间:2015-08-11 11:57:28      阅读:101      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!