I am using javascript to format a C# dateTime field and displays it as dd-mon-yyyy in a grid. But when I pass C# datetime to javascript variable, it is geting converted based on my system timezone. ie, Fri Aug 31 2012 06:59:14 is converted to Fri Aug 31 2012 11:29:14 GMT+0530 (India Standard Time) when my machine is in India Standard Time. How to avoid it? I dont have any option other than using javascript since I am using telerik grid.
Asked
Active
Viewed 247 times
0
-
1I would be shocked if the Telerik grid didn't allow you to specify a format or conversion. – Jon Skeet Nov 19 '12 at 07:22
-
I am using their clienttemplate to bind data to column and it needs directly bind model property to grid or call a javascript method. I cant use any server side extensions – user1817701 Nov 19 '12 at 07:30
1 Answers
1
it do not make any change if you are using c# or anything else as you are using javascript for the conversion every where javascript will be the same..
one other solution is convert the c# date and time to string and in javascript parse that date string to date and see what happens.
check the following code to convert timezone
// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset) {
// create Date object for current location
// here you can pass your own date also
d = new Date();
// convert to msec
// add local time zone offset
// get UTC time in msec
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
nd = new Date(utc + (3600000*offset));
// return time as a string
return "The local time in " + city + " is " + nd.toLocaleString();
}

Hemant Metalia
- 29,730
- 18
- 72
- 91
-
I am calling a JS method \n function formatDatesOnGrid(chashDateTime, format) {alert(chashDateTime);} and the object chashDateTime is a c# dateTime object and the behaviour i told above is happening – user1817701 Nov 19 '12 at 07:47
-
one solution is convert the c# date and time to string and in javascript parse that date string to date and see what happens.. – Hemant Metalia Nov 19 '12 at 08:39