当前位置:网站首页>计算日期或日期格式化
计算日期或日期格式化
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), '蜀都赋')
效果:
边栏推荐
猜你喜欢

2022 latest Beijing Construction welder (construction special operation) simulation question bank and answer analysis

Replicate swin on Huawei ascend910_ transformer

Data analysis and privacy security become the key factors for the success or failure of Web3.0. How do enterprises layout?

stm32F407------SPI

Starting from business needs, open the road of efficient IDC operation and maintenance

In the eyes of 100 users, there are 100 QQS

EDI 对接CommerceHub OrderStream

我也是醉了,Eureka 延迟注册还有这个坑!

Enterprise live broadcast: witness focused products, praise and embrace ecology

EasyUI modification and DataGrid dialog form control use
随机推荐
多项式相加
Three dimensional function display of gray image
Update 3dcat real time cloud rendering V2.1.2 release
用秩讨论线性方程组的解/三个平面的位置关系
Sogou batch push software - Sogou batch push tool [2022 latest]
企业直播风起:目睹聚焦产品,微赞拥抱生态
Briefly describe the implementation principle of redis cluster
博后招募 | 西湖大学机器智能实验室招聘博士后/助理研究员/科研助理
【硬件工程师】关于信号电平驱动能力
Google Earth engine - download the globalmlbuildingfootprints vector collection of global buildings
Technical difficulties and applications of large humanoid robots
接口自动化测试Postman+Newman+Jenkins
win10设备管理认不到GTX1080Ti 显示设备的解决办法
Excel表格 / WPS表格中怎么在下拉滚动时让第一行标题固定住?
【硬件工程师】元器件选型都不会?
8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
Replicate swin on Huawei ascend910_ transformer
Chapter V: process control
Headless mode of new selenium4.3 in egde browser
EasyUI drop-down box, add and put on and off shelves of products