您的位置:首页 > 编程语言 > Python开发

python datetime

2016-02-29 08:22 537 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: