【发布时间】:2020-05-08 18:13:45
【问题描述】:
我正在使用 Moment.js 和 React Native 以下列方式显示/操作日期和时间,但似乎不能正确使用它。下面的代码演示了我对该库的使用。
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import * as moment from 'moment';
import { Card } from 'react-native-paper';
interface event {
title: string,
created: any,
expiration: any
}
const party : event = {
title: '21st Bday Party',
created: moment('2019 03 14'),
expiration: moment('2019 03 15')
}
export default function App() {
return (
<View style={styles.container}>
<Card>
<Text>{party.created.format()}</Text>
</Card>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});
我收到以下错误:TypeError: moment is not a function.我做错了什么?如何解决这个问题?
【问题讨论】:
标签: typescript react-native momentjs