El mié, 17 nov 2021 a las 15:12, Chema Cortes (<pych...@gmail.com>) escribió: > > > > El mié, 17 nov 2021 a las 12:25, Juan Carlos Coruña (<ogg...@gmail.com>) > escribió: >> >> Una de las formas que se ocurre es esta: >> >> from datetime import datetime >> from dateutil.relativedelta import relativedelta >> >> import pytz >> >> # tomamos un datetime arbitrario >> now = datetime.now(tz=pytz.timezone('Europe/Madrid')) >> >> next_monday = now + relativedelta(weekday=0) >> next_monday = next_monday.replace(hour=12, minute=30, second=0, >> microsecond=0) >> >> next_monday.astimezone(tz=pytz.UTC) >> >> Pero hay más variantes. >> > > Con dateutil no necesitas usar pytz: > > from datetime import datetime > from dateutil.relativedelta import relativedelta > from dateutil import tz > > # tomamos un datetime arbitrario > now = datetime.now(tz=tz.gettz('Europe/Madrid')) > > next_monday = now + relativedelta(weekday=0) > next_monday = next_monday.replace(hour=12, minute=30, second=0, microsecond=0) > > next_monday.astimezone(tz=tz.UTC) > >
Hola, La opción de Chema me da error. Es posible que no sirva para python 2.7 >>> from dateutil import tz >>> dir(tz) ['EPOCHORDINAL', 'TZFILES', 'TZPATHS', 'ZERO', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__license__', '__name__', '__package__', '_ttinfo', '_tzicalvtz', '_tzicalvtzcomp', 'datetime', 'gettz', 'os', 'parser', 'relativedelta', 'rrule', 'struct', 'sys', 'time', 'tzfile', 'tzical', 'tzlocal', 'tzoffset', 'tzrange', 'tzstr', 'tzutc', 'tzwin', 'tzwinlocal'] La opción de Juan Carlos sí parece funcionar bien. Muchas gracias a ambos. Un saludo, Jose _______________________________________________ Python-es mailing list Python-es@python.org https://mail.python.org/mailman/listinfo/python-es