1
我將datetime.time
對象的時區轉換爲其他時區。看起來最簡單的方法是從datetime.time
對象創建datetime.datetime
,然後執行轉換。爲什麼datetime.time沒有astimezone?
像這樣:
dt = datetime.datetime.combine(datetime.date.today(), self.data)
utc_dt = dt.astimezone(utc)
self.data = utc_dt.time()
爲什麼不datetime.time有astimezone像datetime.datetime呢?看起來這會讓事情變得更容易。是否因爲沒有日期,時區偏移可能不明確?
因爲時區是日期敏感的。所以「是」。 –
是的。一些時區使用DST,它要求日期與它一起計算精確的偏移量。 –