用法:
tzinfo.dst(dt)返回夏令時 (DST) 調整,作為
timedelta對象或None如果 DST 信息未知。如果 DST 無效,則返回
timedelta(0)。如果 DST 生效,則將偏移量作為timedelta對象返回(有關詳細信息,請參閱utcoffset())。請注意,DST 偏移量(如果適用)已添加到utcoffset()返回的 UTC 偏移量中,因此除非您有興趣單獨獲取 DST 信息,否則無需查閱dst()。例如,datetime.timetuple()調用其tzinfo屬性的dst()方法來確定應如何設置tm_isdst標誌,而tzinfo.fromutc()調用dst()來說明跨時區時的夏令時變化。tzinfo子類的實例tz對標準時間和日光時間進行建模,在這個意義上必須是一致的:tz.utcoffset(dt) - tz.dst(dt)必須為每個
datetimedt和dt.tzinfo == tz返回相同的結果 對於理智的tzinfo子類,此表達式產生時區的 “standard offset”,它不應取決於日期或時間,而僅取決於地理位置.datetime.astimezone()的實現依賴於此,但無法檢測違規;確保它是程序員的責任。如果tzinfo子類不能保證這一點,它可能能夠覆蓋tzinfo.fromutc()的默認實現,以便與astimezone()一起正常工作。dst()的大多數實現可能看起來像以下兩個之一:def dst(self, dt): # a fixed-offset class: doesn't account for DST return timedelta(0)或者:
def dst(self, dt): # Code to set dston and dstoff to the time zone's DST # transition times based on the input dt.year, and expressed # in standard local time. if dston <= dt.replace(tzinfo=None) < dstoff: return timedelta(hours=1) else: return timedelta(0)dst()的默認實現引發NotImplementedError。在 3.7 版中更改:DST 偏移量不限於整數分鍾。
相關用法
- Python datetime.tzinfo.fromutc用法及代碼示例
- Python datetime.tzinfo()用法及代碼示例
- Python datetime.tzname()用法及代碼示例
- Python datetime.time.fromisoformat用法及代碼示例
- Python datetime.timetz()用法及代碼示例
- Python datetime.time.isoformat用法及代碼示例
- Python datetime.timedelta用法及代碼示例
- Python datetime.timedelta()用法及代碼示例
- Python datetime.datetime.ctime用法及代碼示例
- Python datetime.utcoffset()用法及代碼示例
- Python datetime.datetime.fromisoformat用法及代碼示例
- Python datetime.datetime.timetuple用法及代碼示例
- Python datetime.date.isoformat用法及代碼示例
- Python datetime.date.replace用法及代碼示例
- Python datetime.date.ctime用法及代碼示例
- Python datetime.datetime.isoformat用法及代碼示例
- Python datetime.date.fromisoformat用法及代碼示例
- Python datetime.date.isocalendar用法及代碼示例
- Python datetime.datetime.astimezone用法及代碼示例
- Python datetime astimezone()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 datetime.tzinfo.dst。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
