当前位置:网站首页>JS每晚24:00更新某方法
JS每晚24:00更新某方法
2022-08-03 14:37:00 【BMG-Princess】
目录
项目效果
需求描述
由于最小单元到日,所以需要每晚24:00更新最新时间。
解决方案:
export default {
data() {
return {
nowTime: null,
};
},
mounted() {
this.nowData()
this.setTimeout();
},
methods: {
//执行每天24:00 刷新
setTimeout() {
var nowTemp = new Date().getTime() //获取当前时间戳
var tomorrowTemp = new Date(new Date().toLocaleDateString()).getTime() +24 * 60 * 60 * 1000;
var residueTemp = tomorrowTemp - nowTemp //距离当天24:00的时间戳
//执行定时任务
setTimeout(() => {
this.nowData()
//次天0点 执行每天24;00 刷新
setInterval(() => {
this.nowData()
}, 1000 * 60 * 60 * 24);
}, residueTemp)
},
nowData() {
var now = new Date();
var year = now.getFullYear(); //得到年份
var month = now.getMonth() + 1; //得到月份
var date = now.getDate(); //得到日期
var weeks = new Array(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六"
);
var week = weeks[now.getDay()]; //得到星期几
// var hour= now.getHours();//得到小时数
// var minute= now.getMinutes();//得到分钟数
// var second= now.getSeconds();//得到秒数
this.nowTime = year + '年' + month + '月' + date + '日' + ' ' + week
}
}
}
边栏推荐
- PostgreSQL 每周新闻 2022-7-27
- Petri net-2, directed net
- PAT乙级-B1008 数组元素循环右移问题(20)
- HDU 1027 Ignatius and the Princess II(求由1-n组成按字典序排序的第m个序列)
- MySQL【存储过程与函数】
- 三元表达式实现多个条件的判断
- 不安装运行时运行.NET程序
- 如何把MapGIS的区文件转为ArcGIS的SHAPE面文件
- Day1:面试必考真题
- Use Typora+EasyBlogImageForTypora to write a blog and upload pictures quickly without a picture bed
猜你喜欢
随机推荐
想成为网络安全技术爱好者(可能是黑客)的话,需要看什么书?
哥斯拉加密WebShell过杀软
With 1000 lines of code statistics after the xi 'an housing prices, I have a startling discovery...
使用Typora+EasyBlogImageForTypora写博客,无图床快速上传图片
中国菜刀原理与实践
MMA安装及使用优化
LeetCode169:多数元素
atrace和systrace的基本使用方法
冰蝎加密 WebShell 过杀软
大势,又一关乎中美竞争的关键行业,走到关键时刻了
位级运算之计算整数位级表示奇偶性
利用华为云ECS服务器搭建安防视频监控平台【华为云至简致远】
MySQL【存储过程与函数】
leetcode 448. Find All Numbers Disappeared in an Array 找到所有数组中消失的数字(简单)
今日睡眠质量记录75分
A high-performance creation book, ASUS Dreadnought Pro15 2022 is completely enough for daily photo editing and editing!
未来无法预料
图形学-粒子系统 (Particle System)
Huffman树
162_Power Query 快速合并文件夹中表格之自定义函数 TableXlsxCsv_2.0