对于一个生活在Molossia 共和国的人来说,Java 中的以下代码:
String TimeZoneId=TimeZone.getDefault().getID();
System.out.println(TimeZoneId);
将打印
美国/里贾纳
我试过TimeZoneInfo.GetSystemTimeZones()
了,但返回值似乎不是 tzdb id。C#中是否有等效的方法?
.Net 并不自然地支持 TZDB,因为微软有它自己的时区数据库。有关详细信息,请参阅TimeZone 标记 wiki。
如果要使用 TZDB 区域,请使用NodaTime库。你问的确切翻译是:
using NodaTime;
...
var timeZoneId = DateTimeZoneProviders.Tzdb.GetSystemDefault().Id;
Console.WriteLine(timeZoneId);
Typically this can be done using the TimeZone class. This is the closest that you will get with the native libraries from my understanding. Why do you need that specific result?
Take a look at Microsoft Time Zones and the Conversion Table* for the Windows Equivalent as Windows does not fully support the TZID, take a look at the stack overflow question below for more information. I hope this is more useful as I misread your previous question!!! - sorry!
//Get A reference to our timezone object
TimeZone t = TimeZone.CurrentTimeZone;
//Print out the display name
Console.WriteLine(t.StandardName);
http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html
Please refer this previous stackoverflow question .NET TimeZoneInfo from Olson time zone
类似的值由
Calendar.GetTimeZone