safari下设置时间戳不成功时
设置时间戳
var date='2017-6-8';
var Time=new Date(date);
//在fireFox、chrome等浏览器下都显示:
// Thu Jun 08 2017 00:00:00 GMT+0800 (中国标准时间)
//在safari下显示: Invalid Date
以下方法为修复Safari下兼容问题
var arr=[];
arr=date.split('-');
var Time=new Date(parseInt(arr[0]),parseInt(arr[1])-1,parseInt(arr[2]));
console.log(Time);
//返回结果
//safari:Thu Jun 08 2017 00:00:00 GMT+0800 (Öйú±ê׼ʱ¼ä)
//chrome: Thu Jun 08 2017 00:00:00 GMT+0800 (中国标准时间)
设置指定天数的后天
chrome下
var date='2017-6-8';
var Time=new Date(date);
//后天
Time.setDate(Time.getDate()+2);
console.log(Time);
返回结果:Sat Jun 10 2017 00:00:00 GMT+0800 (中国标准时间);
safari下
var arr=[];
arr=date.split('-');
var Time=new Date(parseInt(arr[0]),parseInt(arr[1])-1,parseInt(arr[2])+2);
console.log(Time);
返回结果:Sat Jun 10 2017 00:00:00 GMT+0800 (Öйú±ê׼ʱ¼ä);