首页 > 解决方案 > 如何在 React js 中格式化日期

问题描述

我正在使用 React Date Picker 获取日期,截至目前,我收到的日期为:Fri Feb 01 2019 00:00:00 GMT+0530(印度标准时间),现在我想将其格式化为“”YYYY- MM-DD" 格式。有没有办法在 React js 中实现这一点?

我尝试这样做但没有帮助:

date=this.state.startDate.getDate() + "-"+ parseInt(this.state.startDate.getMonth()+1) +"-"+this.state.startDate.getFullYear();

标签: javascriptreactjs

解决方案


推荐阅读