獲取日期差【每日一個知識點第346期-Python】

oneday = datetime.timedelta(days=1)
#今天,2014-03-21
today = datetime.date.today()
#昨天,2014-03-20
yesterday = datetime.date.today() - oneday
#明天,2014-03-22
tomorrow = datetime.date.today() + oneday
#獲取今天零點的時間,2014-03-21 00:00:00
today_zero_time = datetime.datetime.strftime(today, '%Y-%m-%d %H:%M:%S')

#0:00:00.001000 
print datetime.timedelta(milliseconds=1), #1毫秒
#0:00:01 
print datetime.timedelta(seconds=1), #1秒
#0:01:00 
print datetime.timedelta(minutes=1), #1分鐘
#1:00:00 
print datetime.timedelta(hours=1), #1小時
#1 day, 0:00:00 
print datetime.timedelta(days=1), #1天
#7 days, 0:00:00
print datetime.timedelta(weeks=1)

相關新聞

聯系我們

400-080-6560

在線咨詢:點擊這里給我發消息

郵件:[email protected]

工作時間:周一至周日,09:00-18:30

QR code
云南快乐10分开奖直播