python - Create New Timezone in pytz -
I am trying to create a timezone object for "GMT + 01", however, I can not find it One way to do this is using Patjas I tried to use the cities which () say that are currently in the field but they give strange and irrelevant results to all (they are relative to LMT) )
& gt; & Gt; & Gt; Timezone ('Africa / Algiers') & lt; DstTzInfo 'Africa / Algiers' PMT +0: 09: 00 STD & gt; & Gt; & Gt; & Gt; Timezone ('Africa / Brazzaville') & lt; DstTzInfo 'Africa / Brazzill' LMT + 1: 01: 00 STD & gt; & Gt; & Gt; & Gt; Timezone ('Africa / Conakry') & lt; DstTzInfo 'Africa / Conakry' LMT-1 Day, 23:05:00 STD & gt; & Gt; & Gt; & Gt; Timezone ('Africa / Dola') & lt; DstTzInfo 'Africa / Doula' LMT + 0: 39: 00 STD & gt; Do anyone know how to create a custom timezone with "GMT + 01" or even a relative for the time zone ("GMT"). I tried to add a datetime.timedelta, but that (surprisingly) did not work.
You can select the timezone by using pytz
Then try to manipulate the wire and remove datetime
from the time of GMT function, then you can only select time with GMT + x
In your case, To import datetime import tzinfo, timedelta, datetime, GMT_1_Time_Zone = [] pytz.common_timezones for tz: now = datetime.now () for GMT + 1
import Pytz.timezone (tz)) Now print now "+0100" in "stratetime" ("% z"): GMT_1_Time_Zone.append (( Tz, "(GMT% s)% s"% (now output: [('Africa / Algiers',' (GMT + Africa / Bangui ',' Africa / Bangui ',' Africa / Bangui, Africa (Africa / Brazil), '(GMT + 0100) Africa / Brazzaville', ('Africa / Ceuta', '(GMT + 0100) Africa / Ceuta'), ('Africa / Braun' '(Africa / Lagos', '(Africa / Lagos'), ('Africa / Kinshasa', '(GMT + 0100) Africa / Kinshasa' ('Africa / Lagos', '(GMT + 0100) Africa / Lagos'), (Africa / Libreville ',' (GMT + 0100) Africa / Libreville ', (' Africa / Luanda ',' (GMT + 0100) Africa / Luanda '), (' Africa / Malabo ',' (GMT + 0100) Africa / 'Africa / Nizamena'), ('Africa Africa / Tunisia (Africa / Porto-Novo) Africa / Tripoli, ('GMT + 0100) Africa / Tripoli'), ('Africa / Tunis', '(GMT + 0100) Africa / Niyami' (GMT + 0100) +0100) Africa / Porto-Novo '(' Europe / Amsterdam ',' (GMT + 0100) Europe / Amsterdam '), (' Europe / Andorra ',' (GMT + 0100) ('Europe / Belgrade', 'Europe / Belgrade'), ('Europe / Berlin', '(GMT + 0100) Europe / Berlin'), ('Europe / Beltslava', 'Europe / Belgrade' '(GMT + 0100) Europe / Bratislava', ('Europe / Brussels', '(GMT + 0100) Europe / Brussels'), ('Europe / Budapest', '(GMT + 0100) Europe / Budapest'), ('Europe / Basingen', '(GMT + 0100) Europe (Europe / Copenhagen'), ('Europe / Gibraltar', '(GMT + 0100) Europe / Gibraltar'), ('Europe / Copenhagen'), You (Europe / Madrid, '(GMT + 0100) Europe / Madrid', 'Europe / Copenhagen', 'Europe / Copenhagen', '(Europe / Luxembourg', '(GMT + 0100) Europe / Luxembourg' (GMT + 0100) Europe / Malta, ('Europe / Malta', '(GMT + 0100) Europe / Malta' ('Europe / Monaco', '(GMT + 0100) Europe / Monaco'), (' Europe / Oslo ',' (GMT + 0100) Europe / Oslo '(Europe / Paris,' (GMT + 0100) Europe / Paris'), ('Europe / Podgorica', '(GMT + 0100) Europe / Podgorica') , ('Europe / ('Europe / Rome', '(GMT + 0100) Europe / Rome'), ('Europe / San Marino', '(GMT + 0100) Europe / Prague,' (GMT + 0100) Europe / Prague, , 'Europe / Sarajevo', '(GMT + 0100) Europe / Sarajevo', ('Europe / Skopje', '(GMT + 0100) Europe / Skopje'), ('Europe / Stockholm', ' (Europe / Vatican) (Europe / Stockholm), ('Europe / Tiren', '(GMT + 0100) Europe / Tirane'), ('Europe / Vaduz', '(GMT + 0100) Europe / Vaduz' ',' (GMT + 0100) Europe / Vatican '), (' U Europe / Zagreb ('Europe / Warsaw', '(GMT + 0100) Europe / Warsaw'), ('Europe / Zagreb', '(GMT + 0100) Europe / Zagreb' ), ('Europe / Zurich after digging in this problem', '(GMT + 0100) Europe / Zurich')]
UPDATE I found two better solutions to do this by importing date import time imported from date import import from date import datetime import datetime dt = datetime.strptime ("2014-11-02 21:00 : 00 ","% Y-% m-% d% H:% M:% S ") dt = Pytz.timezone ('etc / GMT + 1'). Localization (DT) dt.isoformat () print dt
dateutil.parser import parse dt from parser
= Pars ("2014-11-02 21:00:00" + "GMT + 0100") dt.isoformat () Print DT
Comments
Post a Comment