当前位置:网站首页>计算日期或日期格式化
计算日期或日期格式化
2022-07-25 17:25:00 【你的美,让我痴迷】
// 计算日期
const calculationDate = val => {
const dd = new Date()
dd.setDate(dd.getDate() - val)
return `${
dd.getFullYear()}-${
(dd.getMonth() + 1) < 10 ? `0${
dd.getMonth() + 1}` : (dd.getMonth() + 1)}-${
dd.getDate() < 10 ? `0${
dd.getDate()}` : dd.getDate()} ${
dd.getHours() < 10 ? `0${
dd.getHours()}` : dd.getHours()}:${
dd.getMinutes() < 10 ? `0${
dd.getMinutes()}` : dd.getMinutes()}:${
dd.getSeconds() < 10 ? `0${
dd.getSeconds()}` : dd.getSeconds()}`
}
// 日期格式化
const formatData = value => {
const dd = new Date(value)
return `${
dd.getFullYear()}-${
(dd.getMonth() + 1) < 10 ? `0${
dd.getMonth() + 1}` : (dd.getMonth() + 1)}-${
dd.getDate() < 10 ? `0${
dd.getDate()}` : dd.getDate()} ${
dd.getHours() < 10 ? `0${
dd.getHours()}` : dd.getHours()}:${
dd.getMinutes() < 10 ? `0${
dd.getMinutes()}` : dd.getMinutes()}:${
dd.getSeconds() < 10 ? `0${
dd.getSeconds()}` : dd.getSeconds()}`
}
实例:
const da = new Date()
da.setHours(da.getHours() - 1)
console.log(formatData(da), calculationDate(0), '蜀都赋')
效果:
边栏推荐
- 如何看一本书
- Hcip notes 12 days
- 电子产品“使用”和“放置”哪个寿命更长??
- I2C通信——时序图
- 多租户软件开发架构
- 【Cadence Allegro PCB设计】永久修改快捷键(自定义)~亲测有效~
- [target detection] yolov5 Runtong voc2007 dataset (repair version)
- Sogou batch push software - Sogou batch push tool [2022 latest]
- Rainbond插件扩展:基于Mysql-Exporter监控Mysql
- Update 3dcat real time cloud rendering V2.1.2 release
猜你喜欢

Dynamic planning topic record
![[knowledge atlas] practice -- Practice of question answering system based on medical knowledge atlas (Part4): problem analysis and retrieval sentence generation combined with problem classification](/img/22/01297d28e5bfb105fc65ee29248a7c.png)
[knowledge atlas] practice -- Practice of question answering system based on medical knowledge atlas (Part4): problem analysis and retrieval sentence generation combined with problem classification

在华为昇腾Ascend910上复现swin_transformer

EasyUI modification and DataGrid dialog form control use

Rainbow plug-in extension: monitor MySQL based on MySQL exporter
![[target detection] yolov5 Runtong visdrone data set](/img/a6/118e6bbeb254f9d1afd1406d1b0089.png)
[target detection] yolov5 Runtong visdrone data set

How to delete Microsoft Pinyin input method in win10

【硬件工程师】元器件选型都不会?

我也是醉了,Eureka 延迟注册还有这个坑!
![[redis] redis installation](/img/4a/750a0b8ca72ec957987fc34e55992f.png)
[redis] redis installation
随机推荐
第五章:流程控制
多项式相加
生成扩散模型漫谈:DDPM = 贝叶斯 + 去噪
Data analysis and privacy security become the key factors for the success or failure of Web3.0. How do enterprises layout?
Enumeration classes and magic values
走马卒
Briefly describe the implementation principle of redis cluster
我想理财,不懂,有没有保本金的理财产品?
01. Sum of two numbers
【VSCODE】支持argparser/接受命令行参数
Talk about how to use redis to realize distributed locks?
博后招募 | 西湖大学机器智能实验室招聘博士后/助理研究员/科研助理
「数字安全」警惕 NFT的七大骗局
新版selenium4.3在egde浏览器的无头模式
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
How to install govendor and open a project
stm32F407------SPI
Technical difficulties and applications of large humanoid robots
Page table cache of Linux kernel source code analysis
枚举类和魔术值