time- module

time- module

学习:

Functions:

time() -- return current time in seconds since the Epoch as a float
clock() -- return CPU time since process start as a float
sleep() -- delay for a number of seconds given as a float
gmtime() -- convert seconds since Epoch to UTC tuple
localtime() -- convert seconds since Epoch to local time tuple
asctime() -- convert time tuple to string
ctime() -- convert time in seconds to string
mktime() -- convert local time tuple to seconds since Epoch
strftime() -- convert time tuple to string according to format specification
strptime() -- parse string to time tuple according to format specification
tzset() -- change the local timezone
2
%a 英文星期简写
%A 英文星期的完全
%b 英文月份的简写
%B 英文月份的完全
%c 显示本地日期时间
%d 日期,取1-31
%H 小时, 0-23
%I 小时, 0-12�0�2
%m 月, 01 -12
%M 分钟,1-59
%j 年中当天的天数
%w 显示今天是星期几
%W 第几周
%x 当天日期
%X 本地的当天时间
%y 年份 00-99间
%Y 年份的完整拼写
 1 #coding: utf-8
 2 import time
 3 import datetime
 4 
 5 print time.time()
 6 print time.clock()
 7 print time.localtime()
 8 print time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
 9 
10 print datetime.datetime(year=2015,month=1,day=1)
11 print datetime.time(hour=1, minute=1, second=1, microsecond=1, )
12 print datetime.date(year=2015, month=1, day=1)
13 print datetime.timedelta(microseconds=-1)
14 print datetime.timedelta(hours=-5)
15 print datetime.datetime.now()
16 print time.strftime("%Y-%m-%d",time.localtime())
17 dtstr = '2014,02-14 21:32:12'
18 print datetime.datetime.strptime(dtstr, "%Y,%m-%d %H:%M:%S")
19 '''
20 日期加减
21 '''
22 d1 = datetime.datetime(2005, 2, 16)
23 d2 = datetime.datetime(2004, 12, 31)
24 print (d1-d2)
25 print (d1-d2).days
26 print (d1-d2).microseconds
27 print (d1-d2).seconds
28 #加一天
29 d1 = datetime.datetime.now()
30 d3 = d1 + datetime.timedelta(days=10)
31 print d3
View Code


 




posted @ 2016-03-16 15:01  gopher-lin  阅读(271)  评论(0编辑  收藏  举报