catamphetamine / javascript-time-ago

International highly customizable relative date/time formatting

Home Page:https://catamphetamine.gitlab.io/react-time-ago/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mongoose timastamps not supported

oussamabouchikhi opened this issue · comments

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

Well, you're passing a String.
Pass something like new Date(message.createdAt).