2019年11月28日 星期四

今天減去7 day (上週)


import datetime, sys

#讀取今日日期

now=datetime.datetime.now()
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

ToDay=datetime.datetime.now().strftime("%Y%m%d")
ToDayTime=datetime.datetime.now().strftime("%Y%m%d-%H%M%S")

print("use [datetime] ToDay=", ToDay)
print("use [datetime] ToDayTime=", ToDayTime)
print("[show Type] ToDay=", type(ToDay))
print("[show Type] ToDayTime=", type(ToDayTime))

# 今天減去7 (上週)
date = now + datetime.timedelta(days=-7)
print("today-7 = ", date)
print("today-7 = ", date.strftime("%Y-%m-%d"))
print("[show Type] today-7 = ", type(date))
print("[show Type] today-7 = ", type(date.strftime("%Y-%m-%d")))


-----------------------------------結果-----------------------------------------------------------

use [datetime] ToDay= 20191128
use [datetime] ToDayTime= 20191128-170106
[show Type] ToDay= <class 'str'>
[show Type] ToDayTime= <class 'str'>
today-7 =  2019-11-21 17:01:06.450264
today-7 =  2019-11-21
[show Type] today-7 =  <class 'datetime.datetime'>
[show Type] today-7 =  <class 'str'>


Process finished with exit code 0

沒有留言:

張貼留言

print(dir(urllib.request.urlopen(url))) 實作

import urllib.request url = 'http://www.baidu.com/' response = urllib.request.urlopen(url) print(type(response)) print(dir(...