当前位置:网站首页>计算日期或日期格式化
计算日期或日期格式化
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), '蜀都赋')
效果:
边栏推荐
- We were tossed all night by a Kong performance bug
- Hcip notes 12 days
- Three dimensional function display of gray image
- Starting from business needs, open the road of efficient IDC operation and maintenance
- pgsql有没有好用的图形化管理工具?
- Enumeration classes and magic values
- With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
- 03.无重复字符的最长子串
- 双向链表的基本操作
- 8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
猜你喜欢
![[target detection] yolov5 Runtong visdrone data set](/img/a6/118e6bbeb254f9d1afd1406d1b0089.png)
[target detection] yolov5 Runtong visdrone data set

Dynamic planning topic record
![[target detection] tph-yolov5: UAV target detection based on Transformer's improved yolov5](/img/be/5348170fb460cbafbdb848d70fea15.png)
[target detection] tph-yolov5: UAV target detection based on Transformer's improved yolov5
![[knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part5 end): information retrieval and result assembly](/img/47/e70f6b86f4dded3218370da7394a07.png)
[knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part5 end): information retrieval and result assembly

Hcip notes 11 days

Using rank to discuss the solution of linear equations / the positional relationship of three planes

Wu Enda logistic regression 2

一篇文章了解超声波加湿器

Rainbond插件扩展:基于Mysql-Exporter监控Mysql

Chapter VI succession
随机推荐
多项式相加
我也是醉了,Eureka 延迟注册还有这个坑!
[knowledge atlas] practice -- Practice of question answering system based on medical knowledge atlas (Part3): rule-based problem classification
POWERBOARD coco! Dino: let target detection embrace transformer
HCIP笔记十一天
我也是醉了,Eureka 延迟注册还有这个坑!
在华为昇腾Ascend910上复现swin_transformer
GTX1080Ti 光纤HDMI干扰出现闪屏1080Ti 闪屏解决方法
[target detection] tph-yolov5: UAV target detection based on Transformer's improved yolov5
电子产品EMC不合格,如何整改?
[Nanjing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
How to install govendor and open a project
03. Longest substring without repeated characters
From digitalization to intelligent operation and maintenance: what are the values and challenges?
Lvgl 7.11 tileview interface cycle switching
04. Find the median of two positive arrays
Outlook tutorial, how to search for calendar items in outlook?
Enumeration classes and magic values
04.寻找两个正序数组的中位数
Don't believe these "rumors" in the process of preparing for the exam!