BK1*_*K19 1 date date-format react-native
我使用以下来显示日期:
var formattedDate = new Date(date).toString();
console.log("DATE >> ", formattedDate);
Run Code Online (Sandbox Code Playgroud)
结果:
'日期 >>' , '2015 年 11 月 23 日星期三 05:30:00'
我的date格式如下:
date= 2015-11-23
Run Code Online (Sandbox Code Playgroud)
但我想格式化我date的"DD MMM YYYY"格式react-native-ios.
使用 date.getDay()、date.getMonth() 和 date.getYear() 从日期中提取年月日,然后随心所欲地使用它:)
var formattedDate = new Date(date);
var newDate = formattedDate.getDay().toString() + " " + formattedDate.getMonth().toString() + " " + formattedDate.getYear().toString();
Run Code Online (Sandbox Code Playgroud)
作为替代方案,您也可以使用 moment.js。有很多有用的功能。
var formattedDate = new Date(date);
var newDate = formattedDate.getDay().toString() + " " + formattedDate.getMonth().toString() + " " + formattedDate.getYear().toString();
Run Code Online (Sandbox Code Playgroud)
导入时刻JS:
var newDate = moment(Date(yourDate)).format('DD-MM-YYYY');Run Code Online (Sandbox Code Playgroud)
安装瞬间JS:
npm install moment
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22860 次 |
| 最近记录: |