Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
105 views
in Technique[技术] by (71.8m points)

python - Finding timezone for a timestamp

How to say what is the timezone for a timestamp?

Ex: lets say I have this "2021-01-18 21:24:02".

Is there any way in python to say its timezone?

question from:https://stackoverflow.com/questions/65948643/finding-timezone-for-a-timestamp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no way Python will know "2021-01-18 21:24:02" comes from which timezone because the information about the timezone is not in the string.

It could be 9:24 PM in USA, or Sydney, or Japan, or South Africa.

The most logical answer is the time came from UTC (or GMT), which is +0 because no timezone is provided.

The string itself must contain the information of timezone according to the format of various standards. See here for reference: https://www.utctime.net/z-time-now

Example: ISO-8601 2021-01-29T04:49:28+0000

which show the timezone as UTC (+0000)

If the datetime is 2021-01-29T04:49:28+0800 , then the timezone is +8 or Singapore/Perth/China/Hong Kong time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...