js获取当天时间 本月第一天 本月最后一天

当天开始时间,如2020-01-01 00:00:00:
new Date(
    new Date(new Date().toLocaleDateString()).getTime()
)

本月第一天:
var nowdate = new Date();
 var y = nowdate.getFullYear();
 var m = nowdate.getMonth()+1;
 var d = nowdate.getDate();
 var formatnowdate = y+'-'+m+'-'+d;
 var dd = formatnowdate.replace(/-/g, '/');
var firstDay =  new Date(dd);

本月最后一天:

var nowdate = new Date();
 //获取系统前一个月的时间
 nowdate.setMonth(nowdate.getMonth()-1);
 var y = nowdate.getFullYear();
 var m = nowdate.getMonth()+1;
 var d = nowdate.getDate();
 var formatwdate = y+'-'+m+'-'+d;
 var dd = formatwdate.replace(/-/g, '/');
var lastDay = new Date(dd);

 

 

你可能感兴趣的:(前端)