The blog of Paul Gansele [1] made me trying an other approach. #!/usr/bin/env python3 # -*- coding: utf_8 -*- ### tested with python3.5 from datetime import datetime, timedelta, timezone from dateutil import tz amsterdam = tz.gettz('Europe/Amsterdam') utc = tz.gettz('utc') amsterdam_datetime = datetime(2018, 12, 17, 11, 31, 26, tzinfo=amsterdam) print(amsterdam_datetime) tuple = amsterdam_datetime.utctimetuple() utc_datetime = datetime(tuple[0], tuple[1], tuple[2], tuple[3], tuple[4], tuple[5]) print(utc_datetime) amsterdam_datetime = datetime(2018, 6, 17, 11, 31, 26, tzinfo=amsterdam) print(amsterdam_datetime) tuple = amsterdam_datetime.utctimetuple() utc_datetime = datetime(tuple[0], tuple[1], tuple[2], tuple[3], tuple[4], tuple[5]) print(utc_datetime)
Output: 2018-12-17 11:31:26+01:00 2018-12-17 10:31:26 2018-06-17 11:31:26+02:00 2018-06-17 09:31:26 [1] pytz: The Fastest Footgun in the West 2018-03-19 https://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html Op 2019-02-07T17:56:21+0000 schreef David Raymond <david.raym...@tomtom.com> in bericht <uri:mid:vi1pr07mb5792f9dec50beee7ac122ecf87...@vi1pr07mb5792.eurprd07.prod.outlook.com>, inzake: <RE: timezones> het volgende. > I'd say if the documentation mentions it, but doesn't say why, then > we're not gonna be able to do much better for you as far as "why" > goes. > > http://pytz.sourceforge.net/ > > "Unfortunately using the tzinfo argument of the standard datetime > constructors "does not work" with pytz for many timezones." > > But it looks like they suggest something along the lines of... > > timezone('Europe/Amsterdam').localize(datetime(2018, 12, 17, 11, 31, > 26)) > > > From the examples on > http://pytz.sourceforge.net/#problems-with-localtime ... > > >>> eastern = timezone('US/Eastern') > >>> fmt = '%Y-%m-%d %H:%M:%S %Z%z' > >>> loc_dt = datetime(2002, 10, 27, 1, 30, 00) > >>> est_dt = eastern.localize(loc_dt, is_dst=True) > >>> edt_dt = eastern.localize(loc_dt, is_dst=False) > >>> print(est_dt.strftime(fmt) + ' / ' + edt_dt.strftime(fmt)) > 2002-10-27 01:30:00 EDT-0400 / 2002-10-27 01:30:00 EST-0500 > > > Browse through their examples and see if you can find something > similar that works for you. > > > -----Original Message----- > From: Python-list > [mailto:python-list-bounces+david.raymond=tomtom....@python.org] On > Behalf Of Jaap van Wingerde Sent: Wednesday, February 06, 2019 9:27 > AM To: python-list@python.org Subject: timezones > > I made a small script to practise with timezones: > > #!/usr/bin/env python3 > # -*- coding: utf_8 -*- > from datetime import datetime, timedelta > from pytz import timezone > import pytz > amsterdam_datetime = datetime(2018, 12, 17, 11, 31, 26, > tzinfo=timezone('Europe/Amsterdam')) > print(amsterdam_datetime) > utc_datetime = amsterdam_datetime.astimezone(pytz.utc) > print(utc_datetime) > amsterdam_datetime = datetime(2018, 6, 17, 11, 31, 26, > tzinfo=timezone('Europe/Amsterdam')) > print(amsterdam_datetime) > utc_datetime = amsterdam_datetime.astimezone(pytz.utc) > print(utc_datetime) > > The output of the script is: > 2018-12-17 11:31:26+00:20 > 2018-12-17 11:11:26+00:00 > 2018-06-17 11:31:26+00:20 > 2018-06-17 11:11:26+00:00 > > I respected: > 2018-12-17 11:31:26+01:00 > 2018-12-17 10:31:26+00:00 > 2018-06-17 11:31:26+02:00 > 2018-06-17 09:31:26+00:00 > > I need this functionality for adjusting wrong timestamps in Android > JPG-images as the 'Exif.GPSInfo.GPSTimeStamp' and > 'Exif.GPSInfo.GPSDateStamp' are missing. > > Why I get this unrespected results? > > Kind regards, > Jaap. -- https://mail.python.org/mailman/listinfo/python-list