-1

I have a string like this:

'2021-07-24'

I want to change this to datetime type like this:

2021-07-24T00:00:00.000+09:00

How to replace str with datetime like that format?

kwsong0314
  • 221
  • 4
  • 11

1 Answers1

0

You can try this:

from datetime import datetime, timezone, timedelta

dt_obj = datetime.fromisoformat('2021-07-24').replace(tzinfo=timezone(timedelta(hours=9))).isoformat()

print(dt_obj)

Output: 2021-07-24T00:00:00+09:00

Sabil
  • 3,750
  • 1
  • 5
  • 16