获取两个时间之间的天数

var startDate = new Date(_startDate).getTime();
var endDate = new Date(_endDate).getTime();
var offsetTime = Math.abs(endDate - startDate);
var days = Math.floor(offsetTime/(1000*60*60*24));

对数字四舍五入,保留两位小数

Math.round() 返回的为整数, toFixed为强制截取

Math.round(num*100)/100.toFixed(2);

日期格式Format:

 fmtDate = function(_datestr, _pattern){
var date = new Date(_datestr);
var year = date.getYear() + 1900;
var month = date.getMonth() + 1 > 12 ? 1 : date.getMonth() + 1;
var day = date.getDate();
_pattern = _partten.replace(/y{1,4}(-)m{1,2}(-)d{1,2}/gi, year + "$1" + month + "$2" + day);
return _pattern;
}

posted on 2017-12-29 12:25  zhaoqiang1980  阅读(142)  评论(0编辑  收藏  举报