Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 如何在React本机IOS中格式化日期_Date_React Native_Date Format - Fatal编程技术网

Date 如何在React本机IOS中格式化日期

Date 如何在React本机IOS中格式化日期,date,react-native,date-format,Date,React Native,Date Format,我已使用以下内容显示日期: var formattedDate = new Date(date).toString(); console.log("DATE >> ", formattedDate); 结果: “日期>>”,“2015年11月23日星期三05:30:00” 我的日期格式如下: date= 2015-11-23 但是我想在react native ios中用格式格式化我的日期“DD MMM YYYY”。使用date.getDay()、date.getMont

我已使用以下内容显示日期:

var formattedDate = new Date(date).toString();
    console.log("DATE >> ", formattedDate);
结果:

“日期>>”,“2015年11月23日星期三05:30:00”

我的
日期
格式如下:

date= 2015-11-23
但是我想在
react native ios中用
格式格式化我的
日期
“DD MMM YYYY”
使用date.getDay()、date.getMonth()和date.getYear()从日期中提取日-月-年,然后随意使用:)

另外,您也可以使用moment.js。有很多有用的功能

var newDate=moment(Date(yourDate)).format('DD-MM-YYYY')使用date.getDay()、date.getMonth()和date.getYear()从日期中提取日-月-年,然后随意使用:)

另外,您也可以使用moment.js。有很多有用的功能


var newDate=moment(Date(yourDate)).format('DD-MM-YYYY')@Ataomega。要获取日期实例的日期,需要使用formattedDate.getDate().toString()而不是formattedDate.getDay().toString()。否则,你将获得一周中的第一天。查看更多详细信息。

@Ataomega。要获取日期实例的日期,需要使用formattedDate.getDate().toString()而不是formattedDate.getDay().toString()。否则,你将获得一周中的第一天。查看更多详细信息。

使用的
format()
函数

npm安装日期fns——保存

import { format } from 'date-fns'

format(new Date(), 'MMMM Do, YYYY H:mma')

Moment很好,但对于常见用途来说非常大,不幸的是,它不是模块化的,所以您必须导入整个包才能使用它。

使用的
format()
函数

npm安装日期fns——保存

import { format } from 'date-fns'

format(new Date(), 'MMMM Do, YYYY H:mma')


Moment很好,但对于常见用途来说非常大,不幸的是,它不是模块化的,所以您必须导入整个软件包才能使用它。

代码:

handleDatePicked = (date) => {
    console.log(date);
    var ds = date.toString();

    var date = moment(new Date(ds.substr(0, 16)));
    console.log("54874=========>"+date.format("DD/MM/YYYY"));

    this.setState({ 'date_of_birth': date.format("DD/MM/YYYY") });

};
输出:

Sun Mar 17 2019 15:38:00 GMT+0530 (India Standard Time)
17/03/2019

代码:

handleDatePicked = (date) => {
    console.log(date);
    var ds = date.toString();

    var date = moment(new Date(ds.substr(0, 16)));
    console.log("54874=========>"+date.format("DD/MM/YYYY"));

    this.setState({ 'date_of_birth': date.format("DD/MM/YYYY") });

};
输出:

Sun Mar 17 2019 15:38:00 GMT+0530 (India Standard Time)
17/03/2019

嘿,你可以利用图书馆时刻: 您可以使用以下格式设置任何日期:

moment().format('yourDateHere, DD:MM:YYYY');

嘿,你可以利用图书馆时刻: 您可以使用以下格式设置任何日期:

moment().format('yourDateHere, DD:MM:YYYY');

可能重复的可能重复使用此:
var newDate=moment(Date(yourDate)).format('DD-MM-YYYY')。我收到错误
未处理的JS异常:找不到变量:moment
@userashu19首次安装并导入moment模块。
formattedDate.getYear().toString()
给我的是120,而不是2020。不确定为什么要这样做:
var newDate=moment(Date(yourDate)).format('DD-MM-YYYY')。我收到错误
未处理的JS异常:找不到变量:moment
@userashu19首次安装并导入moment模块。
formattedDate.getYear().toString()
给我的是120,而不是2020。不知道你为什么在这里约会?我们如何把变量放在这里?这里的日期是多少?我们如何将变量放在这里?