NodaTime: timezone issue using C # NodaTime library

here i give my code and what's going on.

when i pass the timezone id to .net timezone that works with below code

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

      

when i pass the same timezone id india standard time for the time library in the node then i get the error "timezone india standard time unknown to source TZDB: 2014e (mapping: 9723)"

my code looks like this 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 the timezone to the node library for India Standard Time or GMT Standard Time

thank

-2


source to share


2 answers


If you want to pass BCL timezone to Noda Time, you just need to use BCL provider:

DateTimeZone _zone = DateTimeZoneProviders.Bcl[zoneId];

      



This will find the relevant one TimeZoneInfo

, extract its customization rules, and convert it to a Noda time representation. Then you can use it just like you would any other DateTimeZone

.

Note that these time zone IDs are Windows specific. If you can use the IANA Time Zone Identifiers (TZDBs), it will generally make your data more portable to other systems.

+2


source


As the error message says, the line you provided is not in tzdb (Olson database). There is a list on Wikipedia : Indian Standard Time is Asia / Calcutta. Try this as a zone string.



"Etc / GMT" is the string for GMT, which the wiki says is a shortcut for the time zone string "UTC".

+1


source







All Articles