获取30天时间
复制代码function getMonthDays(nS) {
var date = new Date(nS); //获取一个时间对象
let y = date.getFullYear(); // 获取完整的年份(4位,1970)
let m = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1; // 获取月份(0-11,0代表1月,用的时候记得加上1)
let d = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate(); // 获取日(1-31)
return y + '-' + m + '-' + d;
}
let time = 1610176741;
getMonthDays(time * 1000)
let list = [];
for (var j = 0; j <= 30; j++) {
let thirtyDays = new Date(new Date().toLocaleDateString()).getTime() - j * 3600 * 24 * 1000; //前30天
//let thirtyDays = new Date(new Date().toLocaleDateString()).getTime() + j * 3600 * 24 * 1000; //后30天
thirtyDays = getMonthDays(thirtyDays)
list.push(thirtyDays)
}
console.log('获取30天时间',list)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
获取当天时间
复制代码var today = getMonthDays(new Date(new Date().toLocaleDateString()));
console.log('获取当前时间',today)
- 1
- 2
el-time-picker开始时间小于结束时间(selectableRange设置)
element-ui时间组件el-date-picker用x清空后报错解决方法
标签: 时间
上面是“js获取一个月时间(前30天/后30天/当天)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2117.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!