我需要获取月份的起始日期和当前日期才能在api中发送日期来获取数据,有没有方法可以获得月份的起始日期和当前日期以及类似的年份和星期
例如:我需要发送:
var apiUrl = window.$_APIurl+"admin/installStatistics?fromDate=2020-01-01&toDate=2020-07-03";
axios.get(apiUrl, {headers: headers})这个from date和to date是动态的,我使用下拉选择来更改它,如何在react js中发送此日期?
发布于 2020-07-11 13:03:07
这很简单。
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
var first = date.getDate() - date.getDay(); // First day is the day of the month - the day of the week
var last = first + 6; // last day is the first day + 6
var firstDayofWeek = new Date(date.setDate(first)).toUTCString();
var lastdayOfWeek = new Date(date.setDate(last)).toUTCString();
console.log(firstDayofWeek)
console.log(lastdayOfWeek)
https://stackoverflow.com/questions/62845012
复制相似问题