当前位置:网站首页>JS to get the date in the next seven days of the current date
JS to get the date in the next seven days of the current date
2022-06-13 08:33:00 【BUG_ Jia】
getday2() {
let days = [];
var day = new Date();
for(let i=0; i<=144;i+=24){ //144 Is the number of hours in the first six days
let dateItem=new Date(day.getTime() - i * 60 * 60 * 1000); // Use the timestamp of the day minus the previous time in milliseconds ( Hours * branch * second * millisecond )
let y = dateItem.getFullYear(); // Get year
let m = dateItem.getMonth() + 1; // Get month js Month from 0 Start , need +1
let d= dateItem.getDate() + 7; // Get date
m = this.addDate0(m); // Make up zero for odd months
d = this.addDate0(d); // Fill in zeros for odd dates
let valueItem= y + '-' + m + '-' + d; // Combine
days.push(valueItem); // Add to array
}
console.log(' Date of last seven days :',days);
// Arrange the acquired dates in order
let arr=days.reverse();
let obj={};
for (let key in arr) {
obj[key] = arr[key];
};
let newObj = Object.keys(obj).map(val => ({
day: obj[val]
}));
console.log(newObj)
},
// Add to the date 0
addDate0(time) {
if (time.toString().length == 1) {
time = '0' + time.toString();
}
return time;
},
边栏推荐
- 第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
- Time and date processing in JS
- Shell脚本常用开发规范
- 使用kvm创建三台能通局域网的虚拟机
- The method of SolidWorks modifying text font in engineering drawing
- DIY无人机(匿名拓控者P2+F330机架)
- Using KVM to create three virtual machines that can communicate with local area network
- How to dynamically delete data rows in a table through JS (keep the head)
- 学习记录4: einops // cudnn.benchamark=true // hook
- How can the small and medium-sized lighting industry make use of the digital transformation to stand out from the encirclement?
猜你喜欢
Guidance process and service control
Several precise order receiving methods suitable for fresh food wholesale industry
CCNP_ Bt-ospf big experiment (1)
VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案
How to install the bdtab (BD) new tab plug-in in edge browser (Graphic tutorial)
WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]
array_ Pop error: only variables should be passed by reference
How can the small and medium-sized lighting industry make use of the digital transformation to stand out from the encirclement?
ERP basic data Huaxia
How to hide tabs in nailing applet
随机推荐
sizeof、strlen求字符长度
redis. exceptions. ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.
Four ways to install MySQL in Linux
Buuctf web (VII)
抖音关键词搜索列表接口,超详细的接口对接步骤
Wechat upload picture material interface
名次的确定
MySQL queries difference sets (missing data) by linking tables based on an associated field
Daffodil upgrade (self idempotent)
JS - print 99 multiplication table of the for cycle case
Homestead environment setup
Which is the stronger fresh food distribution and sorting management system?
[notes] like the solution to the problem of slow query (index + explicitly specifying query fields)
Logstash configuration reference article
LeetCode-按奇偶排序数组
Buuctf web (VI)
System safety and Application
MySQL installation and configuration under Windows
Redis subscribe connection timeout interrupt problem solution
AcWing 1977. Information relay (base ring tree, parallel search set)