[英]Convert Microsoft JSON Date to Local DateTime Using Moment JS Only
[英]How to convert Json object date using moment js into react native?
我有這樣的 json 對象日期 "2020-02-26T21:40:47" {{itemmap.date}}
如何將其轉換為類似 2020 年 2 月 12 日的內容我不知道在 React Native 中使用 moment js
提前致謝。
查看 MomentJS 文檔: https ://momentjs.com/docs/#/displaying/format/
應該類似於: moment(yourDate).format("DD MMM, YYYY")
這是簡單的靜態示例。 這可能會幫助你..
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import moment from 'moment';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
dateText: '',
};
}
onDOBDatePicked = (date) => {
this.setState({
dateText: moment(date).format('DD-MMM-YYYY')
});
}
componentDidMount () {
const date = "Sun Feb 23 2020 10:12:46 GMT+0800 (CST)";
this.onDOBDatePicked(date);
}
render() {
return (
<View>
<Text style={{ padding : 50 }}>
{this.state.dateText}
</Text>
</View>
);
}
}
我希望這能解決您的問題.. 如有任何疑問,請詢問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.