我正在使用这个:
string url = string.Format("https://maps.googleapis.com/maps/api/timezone/json?location={0},{1}×tamp=1374868635&sensor=false", lat, lon);
using (HttpClient cl = new HttpClient())
{
string json = await cl.GetStringAsync(url).ConfigureAwait(false);
TimeZoneModel timezone = new JavaScriptSerializer().Deserialize<TimeZoneModel>(json);
}
获取用户时区。这很好用。我想转换这个:
"timeZoneName" : "Central European Summer Time"
.net 时区?
在 .net Timezone 中,时区不存在。
我试图通过以下方式获得正确的时区:
TimeZoneInfo tzf = TimeZoneInfo.FindSystemTimeZoneById("Central European Summer Time");
知道如何将谷歌时区转换为 .net 时区吗?这可能吗?
提前谢谢你们!
最佳答案
而不是使用 timeZoneName
, 我建议使用 timeZoneId
,这将是一个 IANA ID,例如 Europe/London
.
然后您有多种选择:
- 自己找到从那个到 Windows 时区 ID 的映射,例如与 TimeZoneConverter
- 使用Noda Time并使用
TzdbDateTimeZoneSource
将时区映射到 Windows 时区,例如与TzdbDateTimeZoneSource.WindowsMapping
.参见 this answer示例代码。 - 使用野田时间并且不要将其映射到 Windows 时区 - 只需使用野田时间
DateTimeZone
相反,并在整个应用程序中使用 Noda Time,以获得更好的日期/时间体验
显然我赞成最后一个选项,但作为 Noda Time 的主要作者,我有偏见......
关于c# - 将谷歌时区转换为 .net 时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42993828/