js格式化时间
function formatDateTime(inputTime) {
var date = new Date(inputTime);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
return y + "-" + m + "-" + d+" "+h+":"+minute+":"+second;
};
js日期操作
var date=new Date(); //增加一天
date.setDate(date.getDate()+1); //增加一月
date.setMonth(date.getMonth()+1); //增加一年
date.setFullYear(date.getFullYear()+1); //判断date是否是今天
IsDateEquals(date,new Date()); //判断date是否是当月日期
IsMonthEquals(date,new Date()); //判断两个日期的年是否相等
date1.getMonth()==date2.getMonth()&&date1.getFullYear()==date2.getFullYear(); //判断两个日期是否相等
date1.getDate()==date2.getDate()&&IsMonthEquals(date1,date2);