Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12231

Get timezone for specific date

$
0
0

I have a list of dates formatted like so:

'2024-01-01`

I need to turn them into ISO datetimes like so:

`2024-01-01T00:00:00-08:00`

I thought this would be easy, I was wrong. I've seen many questions talk about this on SO, but they tend to over look the complexity of daylight savings time (DST).

What can't be used in a solution:

   datetime.now()

Using datetime.now() will give the current timezone, on the date it is today, and will not be relevant to the date in question.

I need to return the proper offest, when converting a specific date, based on what the offset would have been in local time at the date in question. Example:

'2024-01-01' # becomes'2024-01-01T00:00:00-08:00''2024-06-06' # becomes'2024-01-01T00:00:00-07:00'

I have a solution to brute force this by calculating daylight savings time start and finishes. But that's an ugly solution, there has to be some manipulation of the datetime api that works better.


Viewing all articles
Browse latest Browse all 12231

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>