我创建了一个函数,该函数每月产生几天的循环。
这是我的代码
var date = new Date()
var firstDay = new Date(date.getFullYear(), date.getMonth(), 2);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 1);
firstDay.setHours(0, 0, 0, 0)
lastDay.setHours(0, 0, 0, 0)
console.log('Today date: ', date)
console.log('First Day: ', firstDay)
console.log('Last Day: ', lastDay)
为什么第一天和最后一天从17:00开始?
答案 0 :(得分:2)
您可以通过以下操作“强制”日期从零暗百开始:
"Class"
我怀疑您的要求可能会更复杂。在这种情况下,您可以强制用户的浏览器/设备采用特定的时区,例如:
const date = new Date()
date.setHours(0,0,0,0);
由于您提到过,您正在具有不同时区配置的Node.js上运行它,
date.toLocaleString('en-GB', { timeZone: 'UTC' });
答案 1 :(得分:0)
new Date()
这将返回一个代表命令运行系统当前时间的对象。
Thu Feb 28 2019 15:14:30 GMT+0530 (India Standard Time)