NodaTime:使用NodaTime库C#时区相关的问题 [英] NodaTime: Time zone related issue using NodaTime library c#

查看:847
本文介绍了NodaTime:使用NodaTime库C#时区相关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我给我的代码,什么情况发生。

here i am giving my code and what happen.

当我路过时区的ID代码工作如下

when i am passing timezone id to .net time zone that works the code as below

    var zoneId = "India Standard Time";
    var zone = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
    var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zone);
    string xx1 = now.ToLongTimeString();

当我传递同一时区ID 印度标准时间以野田时间库,然后我得到错误时区印度标准时间是未知的源TZDB:2014E(制图:9723)

when i am passing the same time zone id India Standard Time to noda time library then i am getting error "Time zone India Standard Time is unknown to source TZDB: 2014e (mapping: 9723)"

我的代码为野田佳彦时间

my code as follows for noda time

    var zoneId = "India Standard Time";
    DateTimeZone _zone = DateTimeZoneProviders.Tzdb[zoneId];
    ZonedDateTime _now = SystemClock.Instance.Now.InZone(_zone);
   string xx= now.ToLongTimeString();



只是告诉我如何传递时区野田库印度标准时间或格林尼治标准时间

感谢

推荐答案

如果你想传递一个BCL时区野田佳彦时,你只需要使用BCL提供者:

If you want to pass a BCL time zone to Noda Time, you just need to use the BCL provider:

DateTimeZone _zone = DateTimeZoneProviders.Bcl[zoneId];

这将找到相关的的TimeZoneInfo ,提取其调整规则,将其转换成野田的时间表示。然后,您可以使用它就像任何其他的 DateTimeZone

This will find the relevant TimeZoneInfo, extract its adjustment rules, and convert that into a Noda Time representation. You can then use it just like any other DateTimeZone.

请注意,这些时区ID是针对Windows的。如果你能使用IANA(TZDB)时区的ID替代,这将使得一般的便携式数据的详细到其他系统。

Note that these time zone IDs are Windows-specific. If you can uses the IANA (TZDB) time zone IDs instead, that would generally make your data more portable to other systems.

这篇关于NodaTime:使用NodaTime库C#时区相关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆