Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
1

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 3 years have passed since last update.

ISO-8601文字列を日本時間に変換したい

Posted at

ISO-8601文字列を日本時間に変換したい

2020-09-25T18:00:00Z2020-09-26 03:00:00

Pythonでのプログラム

どう考えてもこんなに長いプログラムが必要ではないはずなんだが……

# coding: utf-8
from datetime import datetime, timezone, timedelta
import dateutil.parser

def time_jst(date_str: str):
    date_str.replace('Z', '+00:00')
    t = dateutil.parser.parse(date_str)
    JST = timezone(timedelta(hours=+9))
    t_jst = t.astimezone(JST)
    ret = t_jst.strftime("%Y-%m-%d %H:%M:%S")
    return ret

s = '2020-09-25T18:00:00Z'
print (time_jst(s))
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?