Created
November 11, 2015 07:14
-
-
Save ericf/7d14714f7dc1e7c4328b to your computer and use it in GitHub Desktop.
<TimeAgo> with React Intl v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
injectIntl, | |
FormattedRelative, | |
} from 'react-intl'; | |
const TimeAgo = ({date, intl}) => { | |
let year = intl.formatDate(date, {year: 'numeric'}); | |
let month = intl.formatDate(date, {month: '2-digit'}); | |
let day = intl.formatDate(date, {day: '2-digit'}); | |
let formattedDate = intl.formatDate(date, { | |
year : 'long', | |
month: 'numeric', | |
day : 'numeric' | |
}); | |
return ( | |
<time | |
datetime={`${year}-${month}-${day}`} | |
title={formattedDate} | |
> | |
<FormattedRelative value={date} /> | |
</time> | |
); | |
}; | |
export default injectIntl(TimeAgo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment