Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ## momentjs ```javascript import React, { Component } from "react"; import { View, Text } from "react-native"; //https://stackoverflow.com/questions/45264638/react-native-moment-locale-does-not-work import moment from "moment/min/moment-with-locales"; moment.locale("ko"); export default class DateText extends Component { render() { const dateText = moment(this.props.date).fromNow(); return <Text style={{ fontSize: 12 }}>{dateText}</Text>; } } ``` ## date-fns ```javascript import React, { Component } from "react" import { FlexRow } from "styles/flex" import Icon from "components/common/Icon" import ko from "date-fns/locale/ko" import distanceInWordsToNow from "date-fns/distance_in_words_to_now" interface Props { text: string icon: string } export default class DateText extends Component<Props> { render() { const { text, icon } = this.props var result = distanceInWordsToNow(new Date(text), { locale: ko, }) return ( <FlexRow> <Icon icon={icon} /> <span style={{ margin: "2px" }}> {result} 전 </span> </FlexRow> ) } } ``` open/momentjs-대신-date-fns-사용하기.txt Last modified: 2024/10/05 06:15by 127.0.0.1