加法运算:
var date = new Date(2023, 5, 17, 12, 34, 56);
var nextSecond = new Date(date.getTime() + 1000);
console.log('输出结果:', nextSecond)
//输出结果: Sat Jun 17 2023 12:34:57 GMT+0800 (中国标准时间)
减法运算:
var date1 = new Date(2023, 5, 17, 12, 34, 56);
var date2 = new Date(2023, 5, 18, 12, 34, 56);
var diff = date2.getTime() - date1.getTime();
console.log('输出结果:', diff)
//输出结果: 86400000
时间间隔计算:
var date = new Date(2023, 5, 17, 12, 34, 56);
var now = new Date();
var yearDiff = now.getFullYear() - date.getFullYear();
var monthDiff = now.getMonth() - date.getMonth();
var dayDiff = now.getDate() - date.getDate();
var hourDiff = now.getHours() - date.getHours();
var minuteDiff = now.getMinutes() - date.getMinutes();
var secondDiff = now.getSeconds() - date.getSeconds();
var millisecondDiff = now.getMilliseconds() - date.getMilliseconds();
console.log('输出yearDiff结果:', yearDiff) // 0
console.log('输出monthDiff结果:', monthDiff) // -1
console.log('输出dayDiff结果:', dayDiff) // 0
console.log('输出hourDiff结果:', hourDiff) // 11
console.log('输出minuteDiff结果:', minuteDiff) // -33
console.log('输出secondDiff结果:', secondDiff) // -25
console.log('输出millisecondDiff结果:', millisecondDiff) // 946
JavaScript获取指定网站状态码查询代码(2种实现方法)
上面是“如何利用js语法计算时间”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4520.html
workflows工作流
一块慕斯蛋糕ComfyUI工作流
蝴蝶兰comfyui工作流
沙漠里美丽的图阿雷格女孩ComfyUI工作流
城市里出现一只可爱的小生物ComfyUI工作流
森林里一只空灵的犀鸟ComfyUI工作流
红伞伞蓝杆杆云南蘑菇群ComfyUI工作流
停在音乐节露营地的一辆复古大众巴士由羊毛制成
一条精致透明的朱红色水晶龙
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用css3做一个动态loading效果
利用CSS3代码编写45款按钮效果
canvas黑洞漩涡(canvas+js)
利用js做一个炫酷音乐背景效果
会议人员60s签到倒计时插件
javascript如何利用draggable实现一个拖拽效果
纯css翻书效果






