NodaTime: Time zone related issue using NodaTime l

2019-06-14 19:06发布

here i am giving my code and what happen.

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();

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();

just tell me how to pass timezone to noda library for India Standard Time or GMT Standard Time

thanks

标签: c# nodatime
2条回答
三岁会撩人
2楼-- · 2019-06-14 19:48

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];

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.

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.

查看更多
乱世女痞
3楼-- · 2019-06-14 19:54

As the error message says, the string you supplied is not in the tzdb (Olson database). There is a list of zones on Wikipedia: Indian Standard Time is "Asia/Kolkata". Try that as your zone string.

"Etc/GMT" is the string for GMT which wiki says is a shortcut to the timezone string "UTC".

查看更多
登录 后发表回答