python 實現得到當前時間偏移day天後的日期

2021-08-13 02:30:18 字數 776 閱讀 3414

importdatetime

#以當前時間作為起始點,days=-7向前偏移7天,days=7向後偏移7天

time_now = datetime.datetime.now()

time = (time_now+datetime.timedelta(days=7)).strftime("%y%m%d")

print(time)

安裝dateutil庫,注意不是pip install dateutil,而是pip install python-dateutil
importdatetime

fromdateutil.relativedeltaimportrelativedelta

#以當前時間作為起始點,days=-7向前偏移7天,days=7向後偏移7天

time_now = datetime.datetime.now()

time = (time_now+datetime.timedelta(days=7)).strftime("%y%m%d")

print(time)

#以當前時間為起始點,偏移乙個月

time_1=(time_now+relativedelta(months=-1)).strftime("%y%m%d")

print(time_1)

TIME 得到當前時間

c 中得到當前時間有2種方式 getsystemtime 得到當前系統時間,由於是utc的時間。轉換為本地時間時要加上8小時。可以從電腦時間屬性的時區看到相差多少小時 getlocaltime 得到當前本地時間 c 得到時間的函式有乙個返回引數,是systemtime型別的 systemtime s...

得到當前時間的幾個函式

asctime 將時間和日期以字串格式表示 相關函式 time,ctime,gmtime,localtime 表頭檔案 include 定義函式 char asctime const struct tm timeptr 函式說明 asctime 將引數timeptr所指的tm結構中的資訊轉換成真實世...

C語言得到當前系統時間

void gettime 格式化時間的格式 a 星期幾的簡寫 a 星期幾的全稱 b 月分的簡寫 b 月份的全稱 c 標準的日期的時間串 c 年份的後兩位數字 d 十進位制表示的每月的第幾天 d 月 天 年 e 在兩字元域中,十進位制表示的每月的第幾天 f 年 月 日 g 年份的後兩位數字,使用基於周...