"Choppy" <Choppy_member at newsranger.com> wrote in message news:3CHy6.1580$jz.135481 at www.newsranger.com... > I was wondering whether anyone knew if it's possible to change the timezone in a > Python script. The reason I ask is because my script is required to read dates > with their associated timezones and transform them into GMT. Python has a > funtion called gmtime() in their time module however it only transforms the time > based on the current local timezone. I solved this issue with C++ by setting an > environment variable "TZ" to the appropriate timezone and running the _tzset() > standard C library function to reset the current timezone. I don't see a way of > doing this in Python though. Any help would be appreciated. I don't see a way to have tzset() re-run in Python, either -- it appears to be run once when the time module is initialized, and that's it. If your date-string is in an ISO 8601 format, such as: YYYY-MM-DD HH:MM:SS[+-HH:MM] (where the part in brackets is the timezone), or if you can conveniently transform it to such format, then maybe the mxDateTime module, ISO submodule, ParseDateTimeUTC factory function, can fill your needs; or similarly, if your date strings are or can be conveniently put in ARPA format, the ARPA submodule -- and I quote: """ [Day, ]DD Mon YYYY HH:MM[:SS] ZONE where ZONE can be one of these: MDT, O, EDT, X, Y, CDT, UT, AST, GMT, PST, Z, V, CST, ADT, I, W, T, U, R, S, P, Q, N, EST, L, M, MST, K, H, E, F, G, D, PDT, B, C, UTC, A (the single letter ones being military time zones). Use of explicit time zone names other than UTC and GMT is depreciated, though. The better alternative is providing the offset from UTC being in effect at the given local time: +-HHMM (this is the offset you have to subtract from the given time in order to get UTC). """ again with the ParseDateTimeUTC factory function. See http://www.lemburg.com/files/python/mxDateTime.html for more details, download information, licensing, etc. Alex
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4