我从数据库获得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
所以我的转换不起作用。它显示错误的日期。
答案 0 :(得分: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));
答案 1 :(得分:0)
var offset = (3600000*(+5.30)); // IST gmtOffset value
应该是
var offset = (3600000*(+5.50)); // IST gmtOffset value