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

python datetime

时间:2016-02-29 09:16:05      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

import datetime as DT

#convert character string: ‘20150212 10:12:11‘ to datetime type: pTime
pTime = DT.datetime.strptime(‘20150212 10:12:11‘, ‘%Y%m%d %H:%M:%S‘)

#calculate the number of days between two date:utcnow() and pTime
days = (  DT.datetime.utcnow()-  pTime  ).days

#day of the year
DOY = ( pTime- DT.datetime(pTime.year, 1, 1) ).days+1
#calculate the time after 1h
aftTime = pTime+ DT.timedelta(hours=1)

  

python datetime

标签:

原文地址:http://www.cnblogs.com/liangxw/p/5226277.html

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