How to convert DateTime to daylight saving time based on date (not current locale) in Python

I want to accept dates specified in a locale with daylight saving time (British Summer Time). I will store dates as UTC, but I want to display and accept dates as input in any DST mode for a date.

The "mode" (daylight saving time or not) will depend on the date entered, not on the current mode at the time of entry or display.

I'm not sure if this is given to me for free or if I need to work hard. I have seen readings in both directions. For example, when the clock returns, the same hour happens twice and I don't understand what should happen in this case.

So:

1 - How to convert DateTime (or interpret date and time) to UTC based on daylight saving time at the time the DateTime represents

2 - How to convert UTC DateTime to daylight saving time representation at the moment DateTime represents

+3


source to share


1 answer


Use the module tz

in dateutil (you may need to install python-dateutil):



http://labix.org/python-dateutil#head-587bd3efc48f897f55c179abc520a34330ee0a62

0


source







All Articles