我使用javascript格式化C# dateTime字段,并将其显示为dd在网格中。但是,当我将C#日期时间传递给javascript变量时,它是基于我的系统时区进行转换的。例如,2012年8月31日星期五06:59:14被转换为星期五2012年8月31日11:29:14 GMT+0530 (印度标准时间)当我的机器在印度标准时间。如何避免呢?除了使用javascript之外,我别无选择,因为我使用的是telerik网格。
发布于 2012-11-19 07:36:02
如果您使用的是c#或其他任何东西,它不会做任何更改,因为您在转换时使用的是javascript,每一个javascript都是相同的。
另一个解决方案是将c#日期和时间转换为string,在javascript中解析该日期字符串并查看发生了什么。
检查以下代码以转换时区
// 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();
}参考:http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329
https://stackoverflow.com/questions/13449265
复制相似问题