我想使用TimeZoneInfo.FindSystemTimeZoneById(String)
方法,但我不知道要使用哪些值作为输入?
我在哪里可以获得id
所需FindSystemTimeZoneById
的值列表?
答案 0 :(得分:76)
以下是Windows 8中的列表(我从Windows注册表中提取)
Afghanistan Standard Time Alaskan Standard Time Alaskan Standard Time\Dynamic DST Arab Standard Time Arabian Standard Time Arabic Standard Time Arabic Standard Time\Dynamic DST Argentina Standard Time Argentina Standard Time\Dynamic DST Atlantic Standard Time Atlantic Standard Time\Dynamic DST AUS Central Standard Time AUS Eastern Standard Time AUS Eastern Standard Time\Dynamic DST Azerbaijan Standard Time Azores Standard Time Azores Standard Time\Dynamic DST Bahia Standard Time Bahia Standard Time\Dynamic DST Bangladesh Standard Time Bangladesh Standard Time\Dynamic DST Canada Central Standard Time Cape Verde Standard Time Caucasus Standard Time Caucasus Standard Time\Dynamic DST Cen. Australia Standard Time Cen. Australia Standard Time\Dynamic DST Central America Standard Time Central Asia Standard Time Central Brazilian Standard Time Central Brazilian Standard Time\Dynamic DST Central Europe Standard Time Central European Standard Time Central Pacific Standard Time Central Standard Time Central Standard Time\Dynamic DST Central Standard Time (Mexico) China Standard Time Dateline Standard Time E. Africa Standard Time E. Australia Standard Time E. Europe Standard Time E. South America Standard Time E. South America Standard Time\Dynamic DST Eastern Standard Time Eastern Standard Time\Dynamic DST Egypt Standard Time Egypt Standard Time\Dynamic DST Ekaterinburg Standard Time Ekaterinburg Standard Time\Dynamic DST Fiji Standard Time Fiji Standard Time\Dynamic DST FLE Standard Time Georgian Standard Time GMT Standard Time Greenland Standard Time Greenland Standard Time\Dynamic DST Greenwich Standard Time GTB Standard Time Hawaiian Standard Time India Standard Time Iran Standard Time Iran Standard Time\Dynamic DST Israel Standard Time Israel Standard Time\Dynamic DST Jordan Standard Time Jordan Standard Time\Dynamic DST Kaliningrad Standard Time Kaliningrad Standard Time\Dynamic DST Kamchatka Standard Time Korea Standard Time Libya Standard Time Libya Standard Time\Dynamic DST Magadan Standard Time Magadan Standard Time\Dynamic DST Mauritius Standard Time Mauritius Standard Time\Dynamic DST Mid-Atlantic Standard Time Middle East Standard Time Middle East Standard Time\Dynamic DST Montevideo Standard Time Montevideo Standard Time\Dynamic DST Morocco Standard Time Morocco Standard Time\Dynamic DST Mountain Standard Time Mountain Standard Time\Dynamic DST Mountain Standard Time (Mexico) Myanmar Standard Time N. Central Asia Standard Time N. Central Asia Standard Time\Dynamic DST Namibia Standard Time Namibia Standard Time\Dynamic DST Nepal Standard Time New Zealand Standard Time New Zealand Standard Time\Dynamic DST Newfoundland Standard Time Newfoundland Standard Time\Dynamic DST North Asia East Standard Time North Asia East Standard Time\Dynamic DST North Asia Standard Time North Asia Standard Time\Dynamic DST Pacific SA Standard Time Pacific SA Standard Time\Dynamic DST Pacific Standard Time Pacific Standard Time\Dynamic DST Pacific Standard Time (Mexico) Pakistan Standard Time Pakistan Standard Time\Dynamic DST Paraguay Standard Time Paraguay Standard Time\Dynamic DST Romance Standard Time Russian Standard Time Russian Standard Time\Dynamic DST SA Eastern Standard Time SA Pacific Standard Time SA Western Standard Time Samoa Standard Time Samoa Standard Time\Dynamic DST SE Asia Standard Time Singapore Standard Time South Africa Standard Time Sri Lanka Standard Time Syria Standard Time Syria Standard Time\Dynamic DST Taipei Standard Time Tasmania Standard Time Tasmania Standard Time\Dynamic DST Tokyo Standard Time Tonga Standard Time Turkey Standard Time Turkey Standard Time\Dynamic DST Ulaanbaatar Standard Time US Eastern Standard Time US Eastern Standard Time\Dynamic DST US Mountain Standard Time UTC UTC+12 UTC-02 UTC-11 Venezuela Standard Time Venezuela Standard Time\Dynamic DST Vladivostok Standard Time Vladivostok Standard Time\Dynamic DST W. Australia Standard Time W. Australia Standard Time\Dynamic DST W. Central Africa Standard Time W. Europe Standard Time West Asia Standard Time West Pacific Standard Time Yakutsk Standard Time Yakutsk Standard Time\Dynamic DST
答案 1 :(得分:33)
您可以从TimeZoneInfo
类
var infos = TimeZoneInfo.GetSystemTimeZones();
foreach (var info in infos)
{
Console.WriteLine(info.Id);
}
示例:
var tzInfo = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
或者,如果您只想要一个像DJ KRAZE建议的时区ID列表
var timeZoneIds = TimeZoneInfo.GetSystemTimeZones().Select(t => t.Id);
答案 2 :(得分:11)
可用的时区是:
Console.WriteLine(string.Join("\n",TimeZoneInfo.GetSystemTimeZones().Select(x=>x.Id)));
结果:
Dateline Standard Time
UTC-11
Aleutian Standard Time
Hawaiian Standard Time
Marquesas Standard Time
Alaskan Standard Time
UTC-09
Pacific Standard Time (Mexico)
UTC-08
Pacific Standard Time
US Mountain Standard Time
Mountain Standard Time (Mexico)
Mountain Standard Time
Central America Standard Time
Central Standard Time
Easter Island Standard Time
Central Standard Time (Mexico)
Canada Central Standard Time
SA Pacific Standard Time
Eastern Standard Time (Mexico)
Eastern Standard Time
Haiti Standard Time
Cuba Standard Time
US Eastern Standard Time
Paraguay Standard Time
Atlantic Standard Time
Venezuela Standard Time
Central Brazilian Standard Time
SA Western Standard Time
Pacific SA Standard Time
Turks And Caicos Standard Time
Newfoundland Standard Time
Tocantins Standard Time
E. South America Standard Time
SA Eastern Standard Time
Argentina Standard Time
Greenland Standard Time
Montevideo Standard Time
Saint Pierre Standard Time
Bahia Standard Time
UTC-02
Mid-Atlantic Standard Time
Azores Standard Time
Cape Verde Standard Time
UTC
Morocco Standard Time
GMT Standard Time
Greenwich Standard Time
W. Europe Standard Time
Central Europe Standard Time
Romance Standard Time
Central European Standard Time
W. Central Africa Standard Time
Namibia Standard Time
Jordan Standard Time
GTB Standard Time
Middle East Standard Time
Egypt Standard Time
E. Europe Standard Time
Syria Standard Time
West Bank Standard Time
South Africa Standard Time
FLE Standard Time
Israel Standard Time
Kaliningrad Standard Time
Libya Standard Time
Arabic Standard Time
Turkey Standard Time
Arab Standard Time
Belarus Standard Time
Russian Standard Time
E. Africa Standard Time
Iran Standard Time
Arabian Standard Time
Astrakhan Standard Time
Azerbaijan Standard Time
Russia Time Zone 3
Mauritius Standard Time
Georgian Standard Time
Caucasus Standard Time
Afghanistan Standard Time
West Asia Standard Time
Ekaterinburg Standard Time
Pakistan Standard Time
India Standard Time
Sri Lanka Standard Time
Nepal Standard Time
Central Asia Standard Time
Bangladesh Standard Time
Omsk Standard Time
Myanmar Standard Time
SE Asia Standard Time
Altai Standard Time
W. Mongolia Standard Time
North Asia Standard Time
N. Central Asia Standard Time
Tomsk Standard Time
China Standard Time
North Asia East Standard Time
Singapore Standard Time
W. Australia Standard Time
Taipei Standard Time
Ulaanbaatar Standard Time
North Korea Standard Time
Aus Central W. Standard Time
Transbaikal Standard Time
Tokyo Standard Time
Korea Standard Time
Yakutsk Standard Time
Cen. Australia Standard Time
AUS Central Standard Time
E. Australia Standard Time
AUS Eastern Standard Time
West Pacific Standard Time
Tasmania Standard Time
Vladivostok Standard Time
Lord Howe Standard Time
Bougainville Standard Time
Russia Time Zone 10
Magadan Standard Time
Norfolk Standard Time
Sakhalin Standard Time
Central Pacific Standard Time
Russia Time Zone 11
New Zealand Standard Time
UTC+12
Fiji Standard Time
Kamchatka Standard Time
Chatham Islands Standard Time
Tonga Standard Time
Samoa Standard Time
Line Islands Standard Time
答案 3 :(得分:8)
查看名为TimeZoneInfo.GetSystemTimeZones()
方法的TimeZoneInfo
上的静态方法。
这将从注册表返回操作系统上所有TimeZoneInfo
的列表。它们都存储在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
。
“都柏林,爱丁堡,里斯本,伦敦”时区的“GMT标准时间”就是一个例子。
答案 4 :(得分:3)
要获取最新的时区列表,请从Windows使用tzutil:
tzutil / l
在这里您可以从Microsoft在MSDN中找到官方的时区ID列表: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones
ID | Time zone name ----------|------------------------ 0 | Dateline Standard Time 110 | UTC-11 200 | Hawaiian Standard Time 300 | Alaskan Standard Time 400 | Pacific Standard Time 410 | Pacific Standard Time (Mexico) 500 | Mountain Standard Time 510 | Mountain Standard Time (Mexico) 520 | US Mountain Standard Time 600 | Canada Central Standard Time 610 | Central America Standard Time 620 | Central Standard Time 630 | Central Standard Time (Mexico) 700 | Eastern Standard Time 710 | SA Pacific Standard Time 720 | US Eastern Standard Time 840 | Venezuela Standard Time 800 | Atlantic Standard Time 810 | Central Brazilian Standard Time 820 | Pacific SA Standard Time 830 | SA Western Standard Time 850 | Paraguay Standard Time 900 | Newfoundland Standard Time 910 | E. South America Standard Time 920 | Greenland Standard Time 930 | Montevideo Standard Time 940 | SA Eastern Standard Time 950 | Argentina Standard Time 1000 | Mid-Atlantic Standard Time 1010 | UTC-2 1100 | Azores Standard Time 1110 | Cabo Verde Standard Time 1200 | GMT Standard Time 1210 | Greenwich Standard Time 1220 | Morocco Standard Time 1230 | UTC 1300 | Central Europe Standard Time 1310 | Central European Standard Time 1320 | Romance Standard Time 1330 | W. Central Africa Standard Time 1340 | W. Europe Standard Time 1350 | Namibia Standard Time 1400 | E. Europe Standard Time 1410 | Egypt Standard Time 1420 | FLE Standard Time 1430 | GTB Standard Time 1440 | Israel Standard Time 1450 | Jordan Standard Time 1460 | Middle East Standard Time 1470 | South Africa Standard Time 1480 | Syria Standard Time 1490 | Turkey Standard Time 1500 | Arab Standard Time 1510 | Arabic Standard Time 1520 | E. Africa Standard Time 1530 | Kaliningrad Standard Time 1550 | Iran Standard Time 1540 | Russian Standard Time 1600 | Arabian Standard Time 1610 | Azerbaijan Standard Time 1620 | Caucasus Standard Time 1640 | Georgian Standard Time 1650 | Mauritius Standard Time 1630 | Afghanistan Standard Time 1710 | West Asia Standard Time 1750 | Pakistan Standard Time 1720 | India Standard Time 1730 | Sri Lanka Standard Time 1740 | Nepal Standard Time 1700 | Ekaterinburg Standard Time 1800 | Central Asia Standard Time 1830 | Bangladesh Standard Time 1820 | Myanmar Standard Time 1810 | N. Central Asia Standard Time 1910 | SE Asia Standard Time 1900 | North Asia Standard Time 2000 | China Standard Time 2020 | Singapore Standard Time 2030 | Taipei Standard Time 2040 | W. Australia Standard Time 2050 | Ulaanbaatar Standard Time 2010 | North Asia East Standard Time 2100 | Korea Standard Time 2110 | Tokyo Standard Time 2130 | AUS Central Standard Time 2140 | Cen. Australia Standard Time 2120 | Yakutsk Standard Time 2200 | AUS Eastern Standard Time 2210 | E. Australia Standard Time 2220 | Tasmania Standard Time 2240 | West Pacific Standard Time 2230 | Vladivostok Standard Time 2300 | Central Pacific Standard Time 2310 | Magadan Standard Time 2400 | Fiji Standard Time 2410 | New Zealand Standard Time 2430 | UTC+12 2500 | Tonga Standard Time 2510 | Samoa Standard Time
答案 5 :(得分:2)
可在MSDN网站上找到完整列表:
答案 6 :(得分:1)
就像其他人所说的那样,你可以通过迭代TimeZoneInfo.GetSystemTimeZones()
找到你想要使用的字符串来找到列表。也就是说,如果您只有时差的信息(如GMT + 9或GMT-10)并且在迭代时区后找不到您的时区,您可能需要查看以下网址以查看您需要哪个时区
https://msdn.microsoft.com/en-US/library/ms912391(v=winembedded.11).aspx
答案 7 :(得分:1)
或者你可以像这样传递TimeZoneInfo.Local.Id
:
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneInfo.Local.Id);
DateTime localDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi);
答案 8 :(得分:1)
我应该传入什么值 TimeZoneInfo.FindSystemTimeZoneById(String)?
答案是视情况而定。 Windows 和 MacOS/Linux 具有不同的 ID。
<块引用>我在哪里可以获得所需 id 的值列表 FindSystemTimeZoneById?
我认为 MacOS/Linux 使用 IANA id,您可以在 NodaTime docs 中找到它,或者我想您可以在 IANA official docs 上的某个地方找到它们。对于 Windows id,请查看 Microsoft Time Zone Index Values
在我的 Macbook 上运行以下代码没问题 var europeSthlm = TimeZoneInfo.FindSystemTimeZoneById("Europe/Stockholm");
而运行 var wEuropeStdTime = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
会抛出一个 System.TimeZoneNotFoundException: The time zone ID 'W. Europe Standard Time' was not found on the local computer.
在这里您可以看到如何使用 NodaTime 检索时区列表,以及如何分别在 Windows 和 Mac 上获取 ID:https://stackoverflow.com/a/19697827/2874896
答案 9 :(得分:0)
最新的Microsoft文档以及这些文档的列表可以在https://support.microsoft.com/en-gb/help/973627/microsoft-time-zone-index-values
中找到。当前时区ID字符串如下(如果要查看实际时差,请参阅每个时区ID的十六进制索引,然后单击上面的链接):
萨摩亚标准时间
阿拉斯加标准时间
山地标准时间
美国山区标准时间
加拿大中部标准时间
中美洲标准时间
美国东部标准时间
大西洋标准时间
太平洋地区标准时间
E。南美标准时间
格陵兰标准时间
亚速尔标准时间
GMT标准时间
中欧标准时间
浪漫标准时间
W。中非标准时间
埃及标准时间
GTB标准时间
南非标准时间
阿拉伯标准时间
阿拉伯标准时间
阿拉伯标准时间
阿富汗过渡伊斯兰国标准时间
西亚标准时间
尼泊尔标准时间
斯里兰卡标准时间
缅甸标准时间
北亚标准时间
新加坡标准时间
W。澳大利亚标准时间
韩国标准时间
雅库茨克标准时间
岑。澳大利亚标准时间
E。澳大利亚标准时间
符拉迪沃斯托克标准时间
中太平洋标准时间
新西兰标准时间
阿塞拜疆标准时间
约旦标准时间
山地标准时间(墨西哥)
纳米比亚标准时间
巴西中部标准时间
亚美尼亚标准时间
阿根廷标准时间
巴基斯坦标准时间
UTC
堪察加标准时间
答案 10 :(得分:0)
您可以在下面使用该代码
using System;
namespace TimeZoneIds
{
class Program
{
static void Main(string[] args)
{
foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
Console.WriteLine(z.Id);
}
}
}
答案 11 :(得分:0)
一种从一个时区转换为另一个时区的方法:
import os
import requests
from bs4 import BeautifulSoup, Tag
import json
def getResponse(url):
while True:
try:
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
return soup
except:
print("retrying...")
url = "https://www.propertyfinder.ae/en/rent/apartment-for-rent-dubai-dubai-marina-botanica-tower-7469382.html"
soup = getResponse(url)
script = soup.find_all("script")
jsonStr = script[7].text.split('payload: ')[-1].split(';')[0].rsplit('}',1)[0]
val = json.loads(jsonStr)
properties = val['included']
for prop in properties:
if 'links' in prop.keys():
if 'full_screen' in prop['links'].keys():
print (prop['links']['full_screen'])
我在Win10上,并且用import requests
url = 'https://www.propertyfinder.ae/en/api/search'
payload = {
'er[category_id]': '2',
'filter[furnished]': '0',
'filter[locations_ids][]': '3037',
'filter[price_type]': 'y',
'filter[property_type_id]': '1',
'page[limit]': '9999',
'page[number]': '1',
'sort': 'mr',
'include': 'properties,properties.property_type,properties.property_images,properties.location_tree,properties.agent,properties.broker,smart_ads,smart_ads.agent,smart_ads.broker,smart_ads.property_type,smart_ads.property_images,smart_ads.location_tree,direct_from_developer,direct_from_developer.property_type,direct_from_developer.property_images,direct_from_developer.location_tree,direct_from_developer.agent,direct_from_developer.broker,cts,cts.agent,cts.broker,cts.property_type,cts.property_images,cts.location_tree,similar_properties,similar_properties.agent,similar_properties.broker,similar_properties.property_type,similar_properties.property_images,similar_properties.location_tree,agent_smart_ads,agent_smart_ads.broker,agent_smart_ads.languages,agent_properties_smart_ads,agent_properties_smart_ads.agent,agent_properties_smart_ads.broker,agent_properties_smart_ads.location_tree,agent_properties_smart_ads.property_type'}
val = requests.get(url, params=payload).json()
properties = val['included']
for prop in properties:
if 'links' in prop.keys():
if 'full_screen' in prop['links'].keys():
print (prop['links']['full_screen'])
列出了https://www.propertyfinder.ae/property/eaefddc999df314f589016fbb9df0c1e/1312/894/MODE/62d644/7468078-5a70co.jpg
https://www.propertyfinder.ae/property/9dae7d23cc50000baa36f55cde632fec/1312/894/MODE/b59dc8/7468078-d15a9o.jpg
https://www.propertyfinder.ae/property/2aaaa29b083099436f8dea3d018ba0f0/1312/894/MODE/94e390/7468078-84666o.jpg
https://www.propertyfinder.ae/property/a6ab186660629c4b6d494c2e66bd2b71/1312/894/MODE/97a052/7468078-eb879o.jpg
....
:
DateTime n = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(datetime, "sourceTimeZoneId", "destinationTimeZoneId");
获得时差的代码:
Time Zone Id