-2

I am trying to write code.

I could print like that Mongolian time 2019-09-27T15:09:34.915812+08:00 How to print local time zone? Like that "UTC+8"

2

2 Answers 2

1

You could use

pytz library

from datetime import datetime, timedelta from pytz import timezone import pytz utc_8 = timezone("Singapore") utc_8.zone fmt = '%Y-%m-%d %H:%M:%S %Z%z' loc_dt = utc_8.localize(datetime(2019, 9, 27, 15, 9, 34)) print(loc_dt.strftime(fmt)) #2019-09-27 15:09:34 +08+0800 
Sign up to request clarification or add additional context in comments.

Comments

1
>>> import datetime >>> foo = '2019-09-27T15:09:34.915812+08:00' >>> bar = datetime.datetime.strptime(foo, '%Y-%m-%dT%H:%M:%S.%f%z') >>> bar.tzname() 'UTC+08:00' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.