提问者:小点点

如何切割new Date()以只显示所需文件


我正在尝试将我的this.state.date设置为类似于DD/MM/YYYY的内容。 为了获得日期,我使用了一个库https://github.com/mmazzarolo/react-native-modal-datetime-picker

我目前能够选择我想要的日期和。 但是,当我为它设置日期状态时,会得到如下内容:Sun Jul 18 2020 18:21:15 GMT+:4:00...

我如何自定义这个? 下面是我的代码片段,我在其中将日期状态设置为所选日期:

handleConfirmDate(date){
        this.setState({
            date: new Date(date).toString(),
        })
    }

共1个答案

匿名用户

用这样的方式对此使用can

null

var newDate = new Date(),
    datestring = '';

datestring = newDate.getFullYear() + '-' + (newDate.getMonth()+1) + '-' + newDate.getDate()

console.log(datestring);