0

我从数据库中获取 PST 日期格式,我需要转换 IST 格式。但我的系统也在 IST Formate 中。请检查此http://jsfiddle.net/sfcdD/9/

 var date = "2012-12-12 05:18:28.541"; // PST date formate fetch from db
 var offset = (3600000*(+5.30)); // IST gmtOffset value

 var dateformate = 'dd/mm/yyyy "at" h:MM TT';

 var dateArray = (date).split(' ');
 var year = dateArray[0].split('-');
 var time = dateArray[1].split(':');

 var  d = new Date($.trim(year[0]), $.trim(year[1]-1), $.trim(year[2]), $.trim(time[0]), $.trim(time[1]));

 utc = d.getTime() +(d.getTimezoneOffset()*60000); //d.getTimezoneOffset() is taking local timezone

 nd = new Date(utc + parseInt(offset));

 alert(dateFormat(nd,dateformate));  // dispaly 12/12/2012 at 5:06 AM but need to display 12/12/2012 at 7:48 PM 

所以我的转换不起作用。它显示错误的日期。

4

2 回答 2

1

这个怎么样?

var date = "2012-12-12 05:18:28.541";
var offset = (3600000*(+5.50+8));
var dateformate = 'dd/mm/yyyy "at" h:MM TT';

var dateArray = (date).split(' ');
var year = dateArray[0].split('-');
var time = dateArray[1].split(':');

var d = new Date($.trim(year[0]), $.trim(year[1]-1), $.trim(year[2]), $.trim(time[0]), $.trim(time[1]));
var nd = new Date(d.getTime() + offset);
alert(dateFormat(nd,dateformate));
于 2012-12-12T16:19:33.050 回答
0
var offset = (3600000*(+5.30)); // IST gmtOffset value

应该

var offset = (3600000*(+5.50)); // IST gmtOffset value
于 2012-12-12T15:52:25.867 回答