0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

python タイムゾーンの追加

Last updated at Posted at 2019-12-19

やりたかったこと。

時刻データが日本時間ではなく、かつタイムゾーンも設定されていない情報に、
日本時間を加えて、日本時間で処理したいと思った。

引っかかったこと。

タイムゾーンの追加されていない Timestampオブジェクトにタイムゾーンを追加することを調べるのに、
多少苦労したというか、いろんなやり方が言われたり、使えなかったり、使えても非推奨だったりとめんどくさかったので

コード

これ。以上。

# add timezone
dfdate = dfdate.tz_localize('UTC')
print(dfdate) 
# > 時間は変わらず、標準時間をタイムゾーンが追加された日付が表示される。

dfdate = dfdate.astimezone('Asia/Tokyo')
print(dfdate)
# > 時刻が日本時間に代わり(+9時間)、タイムゾーンも追加されたものが表示

pythonは日付データの取り扱いがなんかややこいということがわかった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?