当前位置:网站首页>js根据当天获取前几天的日期
js根据当天获取前几天的日期
2022-08-11 06:14:00 【Crazy_GirlLL】
js根据当前获取n天前的日期 并封装成为 YYYY-MM-DD格式
export function getAgoDay(n){
let date= new Date();
let seperator = "-"
let newDate = new Date(date.getTime() - n*24*60*60*1000);
let year = newDate.getFullYear();
let month = newDate.getMonth()+1;
let day = newDate.getDate();
return year.toString() + seperator + month.toString() + seperator + day.toString()
}
使用方法
// 获取七天前的日期 数字传递几就是获取几天前
console.log(getAgoDay(7));
边栏推荐
- 详解BLEU的原理和计算
- 每日sql -查询至少有5名下属的经理和选举
- Douyin API interface
- 拼多多API接口大全
- 常见激活函数及其导数
- 已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
- 软件测试基本流程有哪些?北京专业第三方软件检测机构安利
- 快速了解集成学习
- sql--Users who have purchased more than 3 times (inclusive) within 7 days (including the current day), and the purchase amount in the past 7 days exceeds 1,000
- 【软件测试】(北京)字节跳动科技有限公司二面笔试题
猜你喜欢
随机推荐
mmdetection的安装和训练、测试didi数据集的步骤(含结果)
NTT的Another Me技术助力创造歌舞伎演员中村狮童的数字孪生体,将在 “Cho Kabuki 2022 Powered by NTT”舞台剧中首次亮相
Daily SQL - find each of the students school gpa minimum (window)
技术分享 | 实战演练接口自动化如何处理 Form 请求?
2022-08-10 Group 4 Self-cultivation class study notes (every day)
How Unity handles C# under the hood
抖音分享口令url API工具
每日sql-员工奖金过滤和回答率排序第一
Internet phone software or consolidation of attack must be "free" calls security clearance
【推荐系统】:协同过滤和基于内容过滤概述
进制转换间的那点事
Unity3D 学习路线?
详解BLEU的原理和计算
redis + lua实现分布式接口限流实现方案
淘宝sku API 接口(PHP示例)
第一个C函数:如何实现板级初始化?
每日sql -查询至少有5名下属的经理和选举
Attitude solution - gyroscope + Euler method
What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?
pytorch,numpy两种方法实现nms类间+类内