-2

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

Thomas
  • 33,544
  • 126
  • 357
  • 626

2 Answers2

3

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • thanks for answer. what is the difference between IANA (TZDB) and BCL timezone ? – Thomas Feb 02 '15 at 18:41
  • @Thomas: The BCL (Base Class Library) in .NET uses the time zone information in Windows - you access that through TimeZoneInfo. So that's the BCL provider. They're Windows-specific, and fairly limited in some ways. TZDB/IANA is the time zone database hosted at iana.org, also known as ZoneInfo, also known as tz, also known as Olson. They're pretty much the de facto standard outside Windows. – Jon Skeet Feb 02 '15 at 18:43
2

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".

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
  • i am getting timezone from browser and sending to server side code to get current time. browser return timezone like this way "India Standard Time or GMT Standard Time" but here u said i need to give timezone like this way "Asia/Kolkata" or "Etc/GMT" to Noda library. so just guide me how to get timezone from browser in such way which will work with noda library. thanks – Thomas Oct 30 '14 at 07:23
  • can anyone tell me what is the advantage of using Nodatime library instead of DotNet built-in datetime ? – Thomas Oct 30 '14 at 07:31
  • I've answered the question you posed. If you have more questions please ask new questions or better still do some basic research! I'm fairly sure you already asked about the browser timezones, and I gave some help, in a question you then deleted. See also http://stackoverflow.com/q/10416552/397817 – Stephen Kennedy Oct 30 '14 at 09:20
  • In response to your second comment, there is an excellent explanatory/introductory article over at the Noda Time website http://blog.nodatime.org/2011/08/what-wrong-with-datetime-anyway.html However, it may be that you need to use DateTime or DateTimeOffset if you don't have an Olson timezone available. I recommend you refine your requirements, do your research, and if the approach you try doesn't work post a new question asking for further guidance. Hope that helps. – Stephen Kennedy Oct 30 '14 at 10:09
  • thanks i will post a new question on this topic after few days. – Thomas Oct 30 '14 at 11:04
  • @Thomas So now you've totally changed the question and invalidated my answer. The correct procedure here would be to rollback your edit, accept my answer, and ask a new question about the JavaScript side of things. – Stephen Kennedy Oct 30 '14 at 13:51
  • i rollback and now post a new thread. so please see and give me your suggestion. here is my thread url http://stackoverflow.com/questions/26655600/nodatime-how-to-parse-timezone-return-by-browser-by-nodatime-library thanks. – Thomas Oct 30 '14 at 14:26