Arun Rana
Arun Rana

Reputation: 8606

Convert Jquery date to custom timezone by timezone id

I have to display datetime value on my real time page and i have done following jquery function for that.

 function DisplayTimer() {
            var x = new Date();
            $('#<%=lblTimer.ClientID %>').html(x.toString());
            setTimeout('DisplayTimer()', 5000);
        }

now i have timezonid value in my session object how can i convert above date value to custom timezone using timezonid session value and also want set datetime format as per culture of user's browser through this jquery function. I have solution in server side code so using [webmethod] i can do that it will make separate request for that every 5 second so i would like to do that without server side interaction. please help me if anyone done this type of logic.

Thanks in adavance.

Upvotes: 2

Views: 365

Answers (1)

Nitin Vijay
Nitin Vijay

Reputation: 1422

Change your code with:

var ClientDatetime = x.getMonth() + "/" + x.getDate() + "/"  + x.getYear() + " " 
+ x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds();

take one hidden variable hdnClientDateTime with runate = server and set value as following

hdnClientDateTime.value = ClientDatetime;

Now, Pass hdnClientDateTime.value variable in your server side Datetime format function and assign the value into label like this:

$('#<%=lblTimer.ClientID %>').html(Result);

Upvotes: 1

Related Questions