0

this js code return timezone of the client pc.

<script type="text/javascript">
        $(document).ready(function () {
            $("#btnGo").click(function () {

                var objdatetime = new Date();
                var timezone = objdatetime.toTimeString();
                var tzstr = timezone.split("(");
                var timezoneid = tzstr[1].toString().replace(")", "");
                alert(timezoneid);
                return false;
            });
        });
    </script>

the above js code return timezone id like "India Standard Time" or "GMT Standard Time"

when i feed those timezone to noda library like this way

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

then i got error "Time zone India Standard Time is unknown to source TZDB: 2014e (mapping: 9723)"

people said that we should pass the timezone id like this way "Asia/Kolkata" or "Etc/GMT" to Noda Library then it may work but browser return timezone id like this way "India Standard Time" or "GMT Standard Time" by calling the above js code.

so get a js code which will return timezone id in such a way as a result Noda library can parse and return current date and time as per the specified timezone id. thanks

Thomas
  • 33,544
  • 126
  • 357
  • 626
  • "browser return timezone id like" is just because you're using bad code to get the time zone... see the referenced question (which you knew about before asking this one...) – Jon Skeet Oct 30 '14 at 14:31
  • .net in built datetime can parse this kind of timezone info "India Standard Time" but why Noda can't ? – Thomas Oct 30 '14 at 14:33
  • 1
    It can if you use `DateTimeProviders.Bcl` - but don't expect it to work on all platforms, as that's the Windows time zone name, which isn't widely used. – Jon Skeet Oct 30 '14 at 14:34
  • 1
    what kind of timezone id which will work across all the platform. i mean any OS. device etc. this format "Asia/Kolkata" works for across any OS or device ? – Thomas Oct 30 '14 at 14:38
  • 1
    Well that's the point of a time zone detection library - it has enough information to give you an ID from *its* database, which will pretty much always be TZDB (aka zoneinfo, aka IANA) – Jon Skeet Oct 30 '14 at 14:50
  • @JonSkeet In light of the above, is this edit correct and acceptable to you or would you prefer it if I rollback? Alternatively I am happy to delete my answer if you wish to provide a better one. I don't want to plagiarise, but do want to provide good answers for other readers. http://stackoverflow.com/posts/26626997/revisions – Stephen Kennedy Oct 30 '14 at 15:03
  • i though people would rectify me just giving an answer. if i am following wrong js code then you guys give me right js code which will return timezone which will be accepted by Noda Library. – Thomas Oct 30 '14 at 15:07
  • i need a timezone id format which works across all OS platform js code. should i follow this js library jstz.min.js ? – Thomas Oct 30 '14 at 15:09
  • 1
    @Thomas Does this not answer your question about how to get a timezone in JavaScript? http://stackoverflow.com/a/8984850/397817 Instead of waiting for other people to guide you, why aren't you testing it? "This script gives you the zone info key representing your device's time zone setting. The return value is an IANA zone info key (aka the Olson time zone database)." Looks good to me! – Stephen Kennedy Oct 30 '14 at 15:12
  • 1
    @StephenKennedy: It's a reasonable edit if this *is* from the Windows time zone database. It's possible that the same JS would give non-Windows IDs at other times, e.g. the daylight saving name, in other times. – Jon Skeet Oct 30 '14 at 15:22
  • @StephenKennedy: can u tell me syntax to get only date from Noda library and as well as 12hrs & 24hrs format time from Noda Library. thanks. – Thomas Oct 30 '14 at 19:40
  • Not in the comments to a closed question mate, no. Read the manual, see if you can work it out. If not, look for an existing question on SO and try to use the answer. If there is no suitable question already, ask a new question on SO stating what you wish to achieve, the code you tried, and the error or problem you have encountered. This is a reasonable workflow. Getting others to do all the thinking for you is not a good workflow for a professional programmer. I won't be answering any more comments on this question but I wish you luck. – Stephen Kennedy Oct 30 '14 at 19:47

0 Answers0