我们的应用程序生成的日志存在问题。解决方案是我们需要获取下个月的第一天,即使所选的日期是月中。
尝试阅读 Moment 上的文档,但找不到任何可能的解决方案。
var currentDate = new Date();
var start_date = new Date(); //Wed Jun 05 2019 13:23:06 GMT+0800 (Philippine Standard Time)
console.log(start_date);
start_date.setDate(start_date.getDate() - 365); //1496640186958
console.log(start_date.setDate(start_date.getDate() - 365)); //Monday, June 5, 2017 1:23:06.958 PM GMT+08:00
// this output should be July 1, 2017, how can I get the first day of next month here?
start_date = customizeDate.formatDateToString(start_date);
var end_date = dateRange.endDate;
Run Code Online (Sandbox Code Playgroud)
您可以将其与您的自定义格式一起使用
const startOfNextMonth = moment().add(1, 'M').startOf('month').format('YYYY-MM-DD hh:mm:ss');
Run Code Online (Sandbox Code Playgroud)
const startOfNextMonth = moment().add(1, 'M').startOf('month').format('YYYY-MM-DD hh:mm:ss');
Run Code Online (Sandbox Code Playgroud)
const startOfNextMonth = moment().add(1, 'M').startOf('month').format('YYYY-MM-DD hh:mm:ss');
console.log(startOfNextMonth);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7256 次 |
| 最近记录: |