首页 > 解决方案 > 在反应中显示日期的一部分

问题描述

我想以 yyyy-mm-dd 格式显示我的日期

他目前向我介绍如下:

 2020-06-29T21:00:00.000Z   

我想让他给我看:

  2020-06-29

如何在反应中做到这一点???

React 中有一些东西就像 Angular 中的管道?

标签: reactjsdate

解决方案


javascript 日期对象有一些不错的功能可以帮助您。

const d = new Date() // im just declaring a new date, use your method, instead, also be aware of capitalization
const year = d.getFullYear()
const month = d.getMonth() // beware this will output 0 for january, 1 for february...
const date = d.getDate()
console.log(`${year}-${month + 1}-${date}`) // you can check it here

检查此链接以获取更多选项。


推荐阅读