My Little World

日期格式兼容

IE11/chrome/360/火狐兼容日期格式兼容

$scope.date= new Date().toLocaleDateString().replace(/\//g,’-‘);
获取到的”year-month-day”格式支持/chrome/360/火狐,但到了IE11就变成”year年month月day”

var date = new Date();
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
var day = date.getDay();
var dateString=y+”-“+m+”-“+d;
$scope.date= dateString;

这样获取的”year-month-day”格式支持以上四种浏览器