记录分享知识
关于本站 写备忘 注册
首页 > 计算机技术 > 前端开发 > JavaScript

js获取指定天数后的日期时间

原创 lihf8515于2025年02月07日 11:10发表
来源:本站 阅读:101
/* 取得指定天数后的时间 */
function getRecentDay(day) {
var today = new Date();
var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
today.setTime(targetday_milliseconds);
var tYear = today.getFullYear();
var tMonth = today.getMonth();
var tDate = today.getDate();
var tHours = 23;//today.getHours();
var tMinutes = 59;//today.getMinutes();
var tSeconds = 59;//today.getSeconds();
tMonth = doHandleMonth(tMonth + 1);
tDate = doHandleMonth(tDate);
tHours = doHandleMonth(tHours);
tMinutes = doHandleMonth(tMinutes);
tSeconds = doHandleMonth(tSeconds);

return tYear + "-" + tMonth + "-" + tDate + ' ' + tHours + ':' + tMinutes + ':' + tSeconds;
}
function doHandleMonth(month) {
var m = month;
if (month.toString().length == 1) {
m = "0" + month;
}
return m;
}
友情链接: 小财迷收银系统  
Copyright © 2025 HF备忘录. All Rights Reserved.
中华人民共和国工业和信息化部ICP备案序号:皖ICP备2025073039号