Dinesh.net Dinesh.net - 2 years ago 80
Javascript Question

How to show Timer according to timezone

I want to display Timer on Page layout header.
it should be according to user time zone.
"plz help "
How to show timer after user logged?

Answer Source

First You have to get TIme ZOne

 TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("YourTime ZoneName");

  var d = new Date('@DateTime.UtcNow.ToTimeZoneTime(timeZoneInfo)');

    function ShowCurrentTime() {
        d.setSeconds(d.getSeconds() + 1);
        $("#curTime").html((d.getMonth()+1) + "/"+ d.getDate()+"/"+ d.getFullYear() +" "+ d.toLocaleTimeString());
        setTimeout("ShowCurrentTime()", 1000); // Here 1000(milliseconds) means one 1 Sec

Call This Javascript function at body on load

<body onload="ShowCurrentTime();"></body>

And Extension Method For Date time

   public static DateTime ToTimeZoneTime(this DateTime utctime, TimeZoneInfo userTimeZone)

        var timeNow = TimeZoneInfo.ConvertTimeFromUtc(utctime, userTimeZone);

        return timeNow;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download