Mongoose timastamps not supported
oussamabouchikhi opened this issue · comments
Oussama Bouchikhi commented
I am trying to format timastamps using Mongoose createdAt field and I get an error.
I am using React and I wrote the following code
import TimeAgo from 'javascript-time-ago'
import fr from 'javascript-time-ago/locale/fr'
TimeAgo.addDefaultLocale(fr);
const timeAgo = new TimeAgo('fr-FR');
<span className="block text-xs text-right">{timeAgo.format(message.createdAt)}</span>
Then I get this error
Error: Unsupported relative time formatter input: string, 2021-06-17T09:44:51.703Z
Nikolay commented
Well, you're passing a String
.
Pass something like new Date(message.createdAt)
.