首页
> 计算机技术
> 前端开发
> JavaScript
js获取指定天数后的日期时间
原创 lihf8515 2025年02月07日 11:10
来源:本站 阅读:400
/* 取得指定天数后的时间 */
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;
}
上一篇:js遍历无限分级的树状结构数组
作者
昵称:君子如兰
注册时间:2025-01-31 02:47:34
最近更新:2025-11-26 16:58:35
文章总数:92篇
原创 86篇
转载 6篇
阅读排行榜
皖公网安备34130202000765号