python 如何将时区缩写转换为完整格式

j13ufse2  于 2023-02-15  发布在  Python
关注(0)|答案(2)|浏览(165)

我正在使用pyzt从名称中获取所有时区参数,例如亚洲/东京,我可以获取JST,但我想将其转换为日本标准时间。在pyzt中有什么方法可以这样做或其他方法吗?
时区名称:亚洲/东京时区缩写:JST需要它给予“日本标准时间”

mrfwxfqh

mrfwxfqh1#

获取时区全名/长名的方法是pytz.country_timezones[country_code],因此在您的示例中,您希望将'JP'作为country_code提供。
由于您没有提供任何代码示例,我无法判断此答案是否足以帮助您。如果您需要更多帮助,请告诉我,我将相应地修改此答案。

thtygnil

thtygnil2#

我不确定pytz是否可行,但使用Pandas构建Map字典很容易(或者重用底部的字典):

import pandas as pd

df = pd.read_html('https://www.timeanddate.com/time/zones/')[0].iloc[:, :2]
df['Time zone name'] = df['Time zone name'].str.split('\s\s+').str[0]
dmap = df.set_index('Abbreviation')['Time zone name'].to_dict()

用法:

>>> dmap['JST']
'Japan Standard Time'

>>> dmap['CEST']
'Central European Summer Time'

>>> dmap['PDT']
'Pacific Daylight Time'

dmap

dmap = {'A': 'Alpha Time Zone',
        'ACDT': 'Australian Central Daylight Time',
        'ACST': 'Australian Central Standard Time',
        'ACT': 'Australian Central Time',
        'ACWST': 'Australian Central Western Standard Time',
        'ADT': 'Atlantic Daylight Time',
        'AEDT': 'Australian Eastern Daylight Time',
        'AEST': 'Australian Eastern Standard Time',
        'AET': 'Australian Eastern Time',
        'AFT': 'Afghanistan Time',
        'AKDT': 'Alaska Daylight Time',
        'AKST': 'Alaska Standard Time',
        'ALMT': 'Alma-Ata Time',
        'AMST': 'Armenia Summer Time',
        'AMT': 'Armenia Time',
        'ANAST': 'Anadyr Summer Time',
        'ANAT': 'Anadyr Time',
        'AQTT': 'Aqtobe Time',
        'ART': 'Argentina Time',
        'AST': 'Atlantic Standard Time',
        'AT': 'Atlantic Time',
        'AWDT': 'Australian Western Daylight Time',
        'AWST': 'Australian Western Standard Time',
        'AZOST': 'Azores Summer Time',
        'AZOT': 'Azores Time',
        'AZST': 'Azerbaijan Summer Time',
        'AZT': 'Azerbaijan Time',
        'AoE': 'Anywhere on Earth',
        'B': 'Bravo Time Zone',
        'BNT': 'Brunei Darussalam Time',
        'BOT': 'Bolivia Time',
        'BRST': 'Brasília Summer Time',
        'BRT': 'Brasília Time',
        'BST': 'British Summer Time',
        'BTT': 'Bhutan Time',
        'C': 'Charlie Time Zone',
        'CAST': 'Casey Time',
        'CAT': 'Central Africa Time',
        'CCT': 'Cocos Islands Time',
        'CDT': 'Cuba Daylight Time',
        'CEST': 'Central European Summer Time',
        'CET': 'Central European Time',
        'CHADT': 'Chatham Island Daylight Time',
        'CHAST': 'Chatham Island Standard Time',
        'CHOST': 'Choibalsan Summer Time',
        'CHOT': 'Choibalsan Time',
        'CHUT': 'Chuuk Time',
        'CIDST': 'Cayman Islands Daylight Saving Time',
        'CIST': 'Cayman Islands Standard Time',
        'CKT': 'Cook Island Time',
        'CLST': 'Chile Summer Time',
        'CLT': 'Chile Standard Time',
        'COT': 'Colombia Time',
        'CST': 'Cuba Standard Time',
        'CT': 'Central Time',
        'CVT': 'Cape Verde Time',
        'CXT': 'Christmas Island Time',
        'ChST': 'Chamorro Standard Time',
        'D': 'Delta Time Zone',
        'DAVT': 'Davis Time',
        'DDUT': "Dumont-d'Urville Time",
        'E': 'Echo Time Zone',
        'EASST': 'Easter Island Summer Time',
        'EAST': 'Easter Island Standard Time',
        'EAT': 'Eastern Africa Time',
        'ECT': 'Ecuador Time',
        'EDT': 'Eastern Daylight Time',
        'EEST': 'Eastern European Summer Time',
        'EET': 'Eastern European Time',
        'EGST': 'Eastern Greenland Summer Time',
        'EGT': 'East Greenland Time',
        'EST': 'Eastern Standard Time',
        'ET': 'Eastern Time',
        'F': 'Foxtrot Time Zone',
        'FET': 'Further-Eastern European Time',
        'FJST': 'Fiji Summer Time',
        'FJT': 'Fiji Time',
        'FKST': 'Falkland Islands Summer Time',
        'FKT': 'Falkland Island Time',
        'FNT': 'Fernando de Noronha Time',
        'G': 'Golf Time Zone',
        'GALT': 'Galapagos Time',
        'GAMT': 'Gambier Time',
        'GET': 'Georgia Standard Time',
        'GFT': 'French Guiana Time',
        'GILT': 'Gilbert Island Time',
        'GMT': 'Greenwich Mean Time',
        'GST': 'South Georgia Time',
        'GYT': 'Guyana Time',
        'H': 'Hotel Time Zone',
        'HDT': 'Hawaii-Aleutian Daylight Time',
        'HKT': 'Hong Kong Time',
        'HOVST': 'Hovd Summer Time',
        'HOVT': 'Hovd Time',
        'HST': 'Hawaii Standard Time',
        'I': 'India Time Zone',
        'ICT': 'Indochina Time',
        'IDT': 'Israel Daylight Time',
        'IOT': 'Indian Chagos Time',
        'IRDT': 'Iran Daylight Time',
        'IRKST': 'Irkutsk Summer Time',
        'IRKT': 'Irkutsk Time',
        'IRST': 'Iran Standard Time',
        'IST': 'Israel Standard Time',
        'JST': 'Japan Standard Time',
        'K': 'Kilo Time Zone',
        'KGT': 'Kyrgyzstan Time',
        'KOST': 'Kosrae Time',
        'KRAST': 'Krasnoyarsk Summer Time',
        'KRAT': 'Krasnoyarsk Time',
        'KST': 'Korea Standard Time',
        'KUYT': 'Kuybyshev Time',
        'L': 'Lima Time Zone',
        'LHDT': 'Lord Howe Daylight Time',
        'LHST': 'Lord Howe Standard Time',
        'LINT': 'Line Islands Time',
        'M': 'Mike Time Zone',
        'MAGST': 'Magadan Summer Time',
        'MAGT': 'Magadan Time',
        'MART': 'Marquesas Time',
        'MAWT': 'Mawson Time',
        'MDT': 'Mountain Daylight Time',
        'MHT': 'Marshall Islands Time',
        'MMT': 'Myanmar Time',
        'MSD': 'Moscow Daylight Time',
        'MSK': 'Moscow Standard Time',
        'MST': 'Mountain Standard Time',
        'MT': 'Mountain Time',
        'MUT': 'Mauritius Time',
        'MVT': 'Maldives Time',
        'MYT': 'Malaysia Time',
        'N': 'November Time Zone',
        'NCT': 'New Caledonia Time',
        'NDT': 'Newfoundland Daylight Time',
        'NFDT': 'Norfolk Daylight Time',
        'NFT': 'Norfolk Time',
        'NOVST': 'Novosibirsk Summer Time',
        'NOVT': 'Novosibirsk Time',
        'NPT': 'Nepal Time',
        'NRT': 'Nauru Time',
        'NST': 'Newfoundland Standard Time',
        'NUT': 'Niue Time',
        'NZDT': 'New Zealand Daylight Time',
        'NZST': 'New Zealand Standard Time',
        'O': 'Oscar Time Zone',
        'OMSST': 'Omsk Summer Time',
        'OMST': 'Omsk Standard Time',
        'ORAT': 'Oral Time',
        'P': 'Papa Time Zone',
        'PDT': 'Pacific Daylight Time',
        'PET': 'Peru Time',
        'PETST': 'Kamchatka Summer Time',
        'PETT': 'Kamchatka Time',
        'PGT': 'Papua New Guinea Time',
        'PHOT': 'Phoenix Island Time',
        'PHT': 'Philippine Time',
        'PKT': 'Pakistan Standard Time',
        'PMDT': 'Pierre & Miquelon Daylight Time',
        'PMST': 'Pierre & Miquelon Standard Time',
        'PONT': 'Pohnpei Standard Time',
        'PST': 'Pitcairn Standard Time',
        'PT': 'Pacific Time',
        'PWT': 'Palau Time',
        'PYST': 'Paraguay Summer Time',
        'PYT': 'Pyongyang Time',
        'Q': 'Quebec Time Zone',
        'QYZT': 'Qyzylorda Time',
        'R': 'Romeo Time Zone',
        'RET': 'Reunion Time',
        'ROTT': 'Rothera Time',
        'S': 'Sierra Time Zone',
        'SAKT': 'Sakhalin Time',
        'SAMT': 'Samara Time',
        'SAST': 'South Africa Standard Time',
        'SBT': 'Solomon Islands Time',
        'SCT': 'Seychelles Time',
        'SGT': 'Singapore Time',
        'SRET': 'Srednekolymsk Time',
        'SRT': 'Suriname Time',
        'SST': 'Samoa Standard Time',
        'SYOT': 'Syowa Time',
        'T': 'Tango Time Zone',
        'TAHT': 'Tahiti Time',
        'TFT': 'French Southern and Antarctic Time',
        'TJT': 'Tajikistan Time',
        'TKT': 'Tokelau Time',
        'TLT': 'East Timor Time',
        'TMT': 'Turkmenistan Time',
        'TOST': 'Tonga Summer Time',
        'TOT': 'Tonga Time',
        'TRT': 'Turkey Time',
        'TVT': 'Tuvalu Time',
        'U': 'Uniform Time Zone',
        'ULAST': 'Ulaanbaatar Summer Time',
        'ULAT': 'Ulaanbaatar Time',
        'UTC': 'Coordinated Universal Time',
        'UYST': 'Uruguay Summer Time',
        'UYT': 'Uruguay Time',
        'UZT': 'Uzbekistan Time',
        'V': 'Victor Time Zone',
        'VET': 'Venezuelan Standard Time',
        'VLAST': 'Vladivostok Summer Time',
        'VLAT': 'Vladivostok Time',
        'VOST': 'Vostok Time',
        'VUT': 'Vanuatu Time',
        'W': 'Whiskey Time Zone',
        'WAKT': 'Wake Time',
        'WARST': 'Western Argentine Summer Time',
        'WAST': 'West Africa Summer Time',
        'WAT': 'West Africa Time',
        'WEST': 'Western European Summer Time',
        'WET': 'Western European Time',
        'WFT': 'Wallis and Futuna Time',
        'WGST': 'Western Greenland Summer Time',
        'WGT': 'West Greenland Time',
        'WIB': 'Western Indonesian Time',
        'WIT': 'Eastern Indonesian Time',
        'WITA': 'Central Indonesian Time',
        'WST': 'Western Sahara Summer Time',
        'WT': 'Western Sahara Standard Time',
        'X': 'X-ray Time Zone',
        'Y': 'Yankee Time Zone',
        'YAKST': 'Yakutsk Summer Time',
        'YAKT': 'Yakutsk Time',
        'YAPT': 'Yap Time',
        'YEKST': 'Yekaterinburg Summer Time',
        'YEKT': 'Yekaterinburg Time',
        'Z': 'Zulu Time Zone'}

相关问题