有没有方法可以使用时区缩写(PST、EDT、GMT等),并在WP7上使用C#将其转换为当前时间?
我想我可以使用TimeZoneInfo之类的东西来查找偏移量,但实际上如何从缩写中获取偏移量,或者从时区全名(通过将缩写映射到全名来获取)?
不,这不会成功的。对于缩短时区名称,目前还没有达成一致的标准。中国标准时间(China Standard Time)和中央标准时间(Central Standard Time,CST)的通用缩写也很难制作,可能永远模糊不清。请查看此常见缩写列表。
最重要的是,Windows Phone没有Windows拥有的时区数据库(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\time Zones)。你必须自己做。
使用TimeZoneInfo.Id,这就是它的用途。
我希望这不是太多的复制,但基于上面的解决方案,这里是上面实现的
var Abbreviations = new Dictionary<string, string>()
{
{"A","Alpha Time Zone"},
{"ACDT","Australian Central Daylight Time"},
{"ACST","Australian Central Standard Time"},
{"ADT","Atlantic Daylight Time"},
{"ADT","Atlantic Daylight Time"},
{"AEDT","Australian Eastern Daylight Time"},
{"AEST","Australian Eastern Standard Time"},
{"AFT","Afghanistan Time"},
{"AKDT","Alaska Daylight Time"},
{"AKST","Alaska Standard Time"},
{"ALMT","Alma-Ata Time"},
{"AMST","Armenia Summer Time"},
{"AMST","Amazon Summer Time"},
{"AMT","Armenia Time"},
{"AMT","Amazon Time"},
{"ANAST","Anadyr Summer Time"},
{"ANAT","Anadyr Time"},
{"AQTT","Aqtobe Time"},
{"ART","Argentina Time"},
{"AST","Arabia Standard Time"},
{"AST","Atlantic Standard Time"},
{"AST","Atlantic Standard Time"},
{"AST","Atlantic Standard 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"},
{"B","Bravo Time Zone"},
{"BNT","Brunei Darussalam Time"},
{"BOT","Bolivia Time"},
{"BRST","Brasilia Summer Time"},
{"BRT","Brasília time"},
{"BST","Bangladesh Standard 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"},
{"CDT","Central Daylight Time"},
{"CEST","Central European Summer Time"},
{"CET","Central European Time"},
{"CET","Central European Time"},
{"CHADT","Chatham Island Daylight Time"},
{"CHAST","Chatham Island Standard Time"},
{"CKT","Cook Island Time"},
{"CLST","Chile Summer Time"},
{"CLT","Chile Standard Time"},
{"COT","Colombia Time"},
{"CST","China Standard Time"},
{"CST","Central Standard Time"},
{"CST","Cuba Standard Time"},
{"CST","Central Standard Time"},
{"CVT","Cape Verde Time"},
{"CXT","Christmas Island Time"},
{"ChST","Chamorro Standard Time"},
{"D","Delta Time Zone"},
{"DAVT","Davis Time"},
{"E","Echo Time Zone"},
{"EASST","Easter Island Summer Time"},
{"EAST","Easter Island Standard Time"},
{"EAT","Eastern Africa Time"},
{"EAT","East Africa Time"},
{"ECT","Ecuador Time"},
{"EDT","Eastern Daylight Time"},
{"EDT","Eastern Daylight Time"},
{"EDT","Eastern Daylight Time"},
{"EEST","Eastern European Summer Time"},
{"EEST","Eastern European Summer Time"},
{"EEST","Eastern European Summer Time"},
{"EET","Eastern European Time"},
{"EET","Eastern European Time"},
{"EET","Eastern European Time"},
{"EGST","Eastern Greenland Summer Time"},
{"EGT","East Greenland Time"},
{"EST","Eastern Standard Time"},
{"EST","Eastern Standard Time"},
{"EST","Eastern Standard Time"},
{"ET","Tiempo del Este"},
{"ET","Tiempo del Este"},
{"ET","Tiempo Del Este "},
{"F","Foxtrot Time Zone"},
{"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"},
{"GMT","Greenwich Mean Time"},
{"GST","Gulf Standard Time"},
{"GYT","Guyana Time"},
{"H","Hotel Time Zone"},
{"HAA","Heure Avancée de l'Atlantique"},
{"HAA","Heure Avancée de l'Atlantique"},
{"HAC","Heure Avancée du Centre"},
{"HADT","Hawaii-Aleutian Daylight Time"},
{"HAE","Heure Avancée de l'Est "},
{"HAE","Heure Avancée de l'Est "},
{"HAP","Heure Avancée du Pacifique"},
{"HAR","Heure Avancée des Rocheuses"},
{"HAST","Hawaii-Aleutian Standard Time"},
{"HAT","Heure Avancée de Terre-Neuve"},
{"HAY","Heure Avancée du Yukon"},
{"HKT","Hong Kong Time"},
{"HLV","Hora Legal de Venezuela"},
{"HNA","Heure Normale de l'Atlantique"},
{"HNA","Heure Normale de l'Atlantique"},
{"HNA","Heure Normale de l'Atlantique"},
{"HNC","Heure Normale du Centre"},
{"HNC","Heure Normale du Centre"},
{"HNE","Heure Normale de l'Est"},
{"HNE","Heure Normale de l'Est"},
{"HNE","Heure Normale de l'Est"},
{"HNP","Heure Normale du Pacifique"},
{"HNR","Heure Normale des Rocheuses"},
{"HNT","Heure Normale de Terre-Neuve"},
{"HNY","Heure Normale du Yukon"},
{"HOVT","Hovd 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"},
{"IST","India Standard Time"},
{"IST","Irish Standard Time"},
{"JST","Japan Standard Time"},
{"K","Kilo Time Zone"},
{"KGT","Kyrgyzstan 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"},
{"MESZ","Mitteleuropäische Sommerzeit"},
{"MEZ","Mitteleuropäische Zeit"},
{"MHT","Marshall Islands Time"},
{"MMT","Myanmar Time"},
{"MSD","Moscow Daylight Time"},
{"MSK","Moscow Standard Time"},
{"MST","Mountain Standard Time"},
{"MUT","Mauritius Time"},
{"MVT","Maldives Time"},
{"MYT","Malaysia Time"},
{"N","November Time Zone"},
{"NCT","New Caledonia Time"},
{"NDT","Newfoundland Daylight Time"},
{"NFT","Norfolk Time"},
{"NOVST","Novosibirsk Summer Time"},
{"NOVT","Novosibirsk Time"},
{"NPT","Nepal Time "},
{"NST","Newfoundland Standard Time"},
{"NUT","Niue Time"},
{"NZDT","New Zealand Daylight Time"},
{"NZDT","New Zealand Daylight Time"},
{"NZST","New Zealand Standard Time"},
{"NZST","New Zealand Standard Time"},
{"O","Oscar Time Zone"},
{"OMSST","Omsk Summer Time"},
{"OMST","Omsk Standard 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","Pacific Standard Time"},
{"PST","Pitcairn Standard Time"},
{"PT","Tiempo del Pacífico"},
{"PWT","Palau Time"},
{"PYST","Paraguay Summer Time"},
{"PYT","Paraguay Time"},
{"Q","Quebec Time Zone"},
{"R","Romeo Time Zone"},
{"RET","Reunion Time"},
{"S","Sierra Time Zone"},
{"SAMT","Samara Time"},
{"SAST","South Africa Standard Time"},
{"SBT","Solomon IslandsTime"},
{"SCT","Seychelles Time"},
{"SGT","Singapore Time"},
{"SRT","Suriname Time"},
{"SST","Samoa Standard 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"},
{"TVT","Tuvalu Time"},
{"U","Uniform Time Zone"},
{"ULAT","Ulaanbaatar Time"},
{"UTC","Universal Time Coordinated"},
{"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"},
{"VUT","Vanuatu Time"},
{"W","Whiskey Time Zone"},
{"WAST","West Africa Summer Time"},
{"WAT","West Africa Time"},
{"WEST","Western European Summer Time"},
{"WEST","Western European Summer Time"},
{"WESZ","Westeuropäische Sommerzeit"},
{"WET","Western European Time"},
{"WET","Western European Time"},
{"WEZ","Westeuropäische Zeit"},
{"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"},
{"WST","West Samoa 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"}
};
这就是我使用的:
public static readonly Dictionary<string, string> AbbreviationsMap = new Dictionary<string, string>() {
{"ACDT", "+1030"}, // Australian Central Daylight
{"ACST", "+0930"}, // Australian Central Standard
{"ADT", "-0300"}, // (US) Atlantic Daylight
{"AEDT", "+1100"}, // Australian East Daylight
{"AEST", "+1000"}, // Australian East Standard
{"AHDT", "-0900"},
{"AHST", "-1000"},
{"AST", "-0400"}, // (US) Atlantic Standard
{"AT", "-0200"}, // Azores
{"AWDT", "+0900"}, // Australian West Daylight
{"AWST", "+0800"}, // Australian West Standard
{"BAT", "+0300"}, // Bhagdad
{"BDST", "+0200"}, // British Double Summer
{"BET", "-1100"}, // Bering Standard
{"BST", "-0300"}, // Brazil Standard
{"BT", "+0300"}, // Baghdad
{"BZT2", "-0300"}, //Brazil Zone 2
{"CADT", "+1030"}, // Central Australian Daylight
{"CAST", "+0930"}, // Central Australian Standard
{"CAT", "-1000"}, // Central Alaska
{"CCT", "+0800"}, // China Coast
{"CDT", "-0500"}, // (US) Central Daylight
{"CED", "+0200"}, // Central European Daylight
{"CET", "+0100"}, // Central European
{"CST", "-0600"}, // (US) Central Standard
{"CENTRAL", "-0600"}, // (US) Central Standard
{"EAST", "+1000"}, // Eastern Australian Standard
{"EDT", "-0400"}, // (US) Eastern Daylight
{"EED", "+0300"}, // Eastern European Daylight
{"EET", "+0200"}, // Eastern Europe
{"EEST", "+0300"}, // Eastern Europe Summer
{"EST", "-0500"}, // (US) Eastern Standard
{"EASTERN", "-0500"}, // (US) Eastern Standard
{"FST", "+0200"}, // French Summer
{"FWT", "+0100"}, // French Winter
{"GMT", "-0000"}, // Greenwich Mean
{"GST", "+1000"}, // Guam Standard
{"HDT", "-0900"}, // Hawaii Daylight
{"HST", "-1000"}, // Hawaii Standard
{"IDLE", "+1200"}, // Internation Date Line East
{"IDLW", "-1200"}, // Internation Date Line West
{"IST", "+0530"}, // Indian Standard
{"IT", "+0330"}, // Iran
{"JST", "+0900"}, // Japan Standard
{"JT", "+0700"}, // Java
{"MDT", "-0600"}, // (US) Mountain Daylight
{"MED", "+0200"}, // Middle European Daylight
{"MET", "+0100"}, // Middle European
{"MEST", "+0200"}, // Middle European Summer
{"MEWT", "+0100"}, // Middle European Winter
{"MST", "-0700"}, // (US) Mountain Standard
{"MOUNTAIN", "-0700"}, // (US) Mountain Standard
{"MT", "+0800"}, // Moluccas
{"NDT", "-0230"}, // Newfoundland Daylight
{"NFT", "-0330"}, // Newfoundland
{"NT", "-1100"}, // Nome
{"NST", "+0630"}, // North Sumatra
{"NZ", "+1100"}, // New Zealand
{"NZST", "+1200"}, // New Zealand Standard
{"NZDT", "+1300"}, // New Zealand Daylight
{"NZT", "+1200"}, // New Zealand
{"PDT", "-0700"}, // (US) Pacific Daylight
{"PST", "-0800"}, // (US) Pacific Standard
{"PACIFIC", "-0800"}, // (US) Pacific Standard
{"ROK", "+0900"}, // Republic of Korea
{"SAD", "+1000"}, // South Australia Daylight
{"SAST", "+0900"}, // South Australia Standard
{"SAT", "+0900"}, // South Australia Standard
{"SDT", "+1000"}, // South Australia Daylight
{"SST", "+0200"}, // Swedish Summer
{"SWT", "+0100"}, // Swedish Winter
{"USZ3", "+0400"}, //USSR Zone 3
{"USZ4", "+0500"}, //USSR Zone 4
{"USZ5", "+0600"}, //USSR Zone 5
{"USZ6", "+0700"}, //USSR Zone 6
{"UT", "-0000"}, // Universal Coordinated
{"UTC", "-0000"}, // Universal Coordinated
{"UZ10", "+1100"}, //USSR Zone 10
{"WAT", "-0100"}, // West Africa
{"WET", "-0000"}, // West European
{"WST", "+0800"}, // West Australian Standard
{"YDT", "-0800"}, // Yukon Daylight
{"YST", "-0900"}, // Yukon Standard
{"ZP4", "+0400"}, // USSR Zone 3
{"ZP5", "+0500"}, //USSR Zone 4
{"ZP6", "+0600"} //USSR Zone 5
};