当前位置:网站首页>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));
边栏推荐
- C语言每日一练——Day02:求最小公倍数(3种方法)
- 拼多多api接口应用示例
- 《Show, Attend and Tell: Neural Image Caption Generation with Visual Attention》论文阅读(详细)
- Discourse 的关闭主题(Close Topic )和重新开放主题
- Do not add the is prefix to the variables of the boolean type in the POJO class of the Alibaba specification
- 姿态解算-陀螺仪+欧拉法
- radix-4 FFT 原理和C语言代码实现
- Douyin get douyin share password url API return value description
- Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months
- Discourse's Close Topic and Reopen Topic
猜你喜欢
随机推荐
maxwell concept
网络电话软件或迎整顿 “免费”通话须迈安全关
maxwell 概念
淘宝商品详情API接口
Redis + lua implements distributed interface current limiting implementation scheme
Taobao product details API interface
Discourse's Close Topic and Reopen Topic
Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
Shell:三剑客之awk
第一个C函数:如何实现板级初始化?
Unity游戏排行榜的制作与优化
Get Pinduoduo product information operation details
矩阵分析——Jordan标准形
unable to extend table xxx by 1024 in tablespace xxxx
Implement general-purpose, high-performance sorting and quicksort optimizations
Daily sql - judgment + aggregation
从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系
软件测试主要做什么工作,难不难?
Depth (relay supervision)
每日sql -查询至少有5名下属的经理和选举