js获取本月第一天和当前时间
//获取本月第一天,格式为年月日
function getFirst() { var date = new Date(); date.setDate(1); var cTime = new Date(new Date(date).toLocaleDateString()).getTime(); //将时间戳转换成时间格式 var date1 = new Date(cTime); var year = date1.getFullYear(); var month = date1.getMonth() + 1; var day = date1.getDate(); month = month < 10 ? "0" + month : month; day = day < 10 ? "0" + day : day; var ddate = year + '-' + month + '-' + day; return ddate; }
//获取当前时间,格式为年月日
function getNow() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); month = month < 10 ? "0" + month : month; day = day < 10 ? "0" + day : day; var ddate = year + '-' + month + '-' + day; return ddate; }