var d1= new Date();
var d2= new Date('1/23/2017 2:10:23 PM'); // server date
var diff = Math.abs(new Date(d1) - new Date(d2));
我想设置 javascript日期(d1)与serverdate(d2)相同但是时间上有细微差别。所以我采取了不同,并希望在javascript日期中添加该差异。我怎么能那样做?
答案 0 :(得分:1)
var d1= new Date();
var d2= new Date('1/23/2017 2:10:23 PM'); // server date
var diff = Math.abs(new Date(d1) - new Date(d2));
var newDate = new Date(d1.getTime() + diff);
console.log(newDate);