码迷,mamicode.com
首页 > 其他好文 > 详细

datetime处理日期和时间

时间:2017-09-30 23:05:32      阅读:482      评论:0      收藏:0      [点我收藏+]

标签:pre   2017年   style   src   处理   ptime   logs   bsp   class   

 1 from datetime import datetime
 2 a=datetime.now()
 3 b=datetime.utcnow()
 4 print(a)
 5 print(b)
 6 c=datetime(2015,5,23,12,20)
 7 print(c)
 8 
 9 d=datetime.strptime(2017/9/30,%Y/%m/%d)
10 e=datetime.strptime(2017年9月30日星期六,%Y年%m月%d日星期六)
11 f=datetime.strptime(2017年9月30日星期六8时42分24秒,%Y年%m月%d日星期六%H时%M分%S秒)
12 g=datetime.strptime(9/30/2017,%m/%d/%Y)
13 h=datetime.strptime(9/30/2017 8:42:50,%m/%d/%Y %H:%M:%S)
14 print(d)
15 print(e)
16 print(f)
17 print(g)
18 print(h)
19 
20 d1=datetime(2017,9,28,10,3,43)
21 print(d1.strftime(%Y年%m月%d日 星期%u %H时%M分%S秒))
22 d2=datetime(2017,9,30)
23 print(d2.strftime(%A,%B,%d,%Y))
24 d3=datetime(2017,9,30,9,22,17)
25 print(d3.strftime(%m/%d/%Y %H:%M:%S %p))
26 
27 t=datetime(2017,9,30)
28 print(t.strftime(今天是%Y年%m月%d日))
29 print(t.strftime(今天是这周的第%w天))
30 print(t.strftime(今天是今年的第%j天))
31 print(t.strftime(今周是今年的%W周))  
32 print(t.strftime(今天是当月的第%d天))
技术分享

 


 

datetime处理日期和时间

标签:pre   2017年   style   src   处理   ptime   logs   bsp   class   

原文地址:http://www.cnblogs.com/zheng01/p/7616259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!