python時間型別處理
阿新 • • 發佈:2019-02-12
**(1)strftime**
**(2)datetime.now()**
**(3)時間相加減**
**注意到datetime是模組,datetime模組還包含一個datetime類,通過from datetime import datetime匯入的才是datetime這個類。**
**如果僅匯入import datetime,則必須引用全名datetime.datetime。**
**datetime.now()返回當前日期和時間,其型別是datetime。**
YEAR = int(datetime.datetime.now().year)
features.established_years = datetime.datetime.now ().year - int(es_date_str)
date2 = str(datetime.now())
date = datetime.strptime(date.split(' ')[0], format)
date2 = datetime.strptime(date2.split(' ')[0], format)
days_diff = (date2 - date).days
self.nowtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
from datetime import timedelta
update_time = datetime.datetime.now () - datetime.timedelta(days=31)
last_time = get_time_now.return_value.strftime('%Y-%m-%d')