0
arrow.get('2016-01-01')
arrow.get(datetime.now(), 'US/Pacific')

arrow.get(datetime.now(), 'China')
arrow.get(datetime.now(), 'CT')
arrow.get(datetime.now(), 'CST')

So, the first two statements work, but the remaining 3 which are trying to convert time to China time do not. How do I fix this?

mtrw
  • 34,200
  • 7
  • 63
  • 71
user308827
  • 21,227
  • 87
  • 254
  • 417
  • According to the Arrow docs at https://arrow.readthedocs.io/en/latest/, Arrow uses the timezone names in the tz database. Those names can be found at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones – mtrw Mar 26 '17 at 23:44

2 Answers2

3

Try using Asia/Shanghai or zh-cn as timezones string.

nick
  • 789
  • 1
  • 11
  • 27
0

full version solutions

use pip install Python arrow package

$ pip install -U arrow
  1. use Python REPL
$ python
>>> import arrow
>>> from datetime import datetime
>>> now = arrow.get(datetime.now(), 'Asia/Shanghai')
>>> print("now =", now)

>>> now = 2023-04-13T00:01:45.222910+08:00

>>> quit()

  1. run test.py as a shell script
$ touch test.py

$ vim ./test.py

$ chmod +x ./test.py
# now = 2023-04-13T00:01:45.222910+08:00

test.py

#!/usr/bin/env python3
# coding: utf8

import arrow
from datetime import datetime

# ✅
now = arrow.get(datetime.now(), 'Asia/Shanghai')
print("now =", now)

# ❌
# arrow.get(datetime.now(), 'zh-cn')

screenshots

enter image description here

enter image description here

refs

https://arrow.readthedocs.io/en/latest/

xgqfrms
  • 10,077
  • 1
  • 69
  • 68