reactjs - 在反应中显示日期的一部分
问题描述
我想以 yyyy-mm-dd 格式显示我的日期
他目前向我介绍如下:
2020-06-29T21:00:00.000Z
我想让他给我看:
2020-06-29
如何在反应中做到这一点???
React 中有一些东西就像 Angular 中的管道?
解决方案
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
检查此链接以获取更多选项。
推荐阅读
- java - 通过 Jenkins 参数化 JUnit CucumberOptions
- json - 使用 Swift 解码器从 JSON 数组中提取属性
- node.js - 使用 sinon fake 进行单元测试无法解决承诺
- pytorch - 如何使用 Pytorch 将 FloatTensor 转换为 ByteTensor?
- ansible - ansible vmware windows 服务器
- java - 如何使用 findElements 检查下拉菜单中的复选框并获取?(java/seleniumWebDriver)
- php - 如何将 Wordpress 数据库导入纯 PHP MySQL 网站?
- java - Appcenter 测试失败:分叉进程中出现错误
- objective-c - 突出显示 CPTScatterPlot 的部分
- optimization - 获取lmfit使用非“Leastsq”方法得到的协方差最佳拟合参数