Nodatime: how to parse browser timezone return from NodaTime Library

this js code returns timezone for 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 time code like "India Standard Time" or "Default Standard Time"

when i pass this timezone to the node library like this path

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

      

then I got the error "Time zone India Standard time unknown to source TZDB: 2014e (mapping: 9723)"

people said that we have to pass the timezone id like "Asia / Kolkata" or "Etc / GMT" to the Noda library, then it might work, but the browser returns the timezone id like "India Standard Time" or "GMT Standard" Time "by calling the above js code.

then you will get js code that will return the timezone ID in such a way that as a result the Noda library can parse and return the current date and time according to the specified timezone ID. thank

0


source to share





All Articles