Home > Software engineering >  How do I output momentjs in arabic?
How do I output momentjs in arabic?

Time:11-17

I'm trying to show how many time went since the creation on a post! after searching I found that I have to use momentJs. The time is stored like this:

enter image description here

And I used this code to show the time

{moment.utc(post.createdAt).local().startOf('seconds').fromNow()}

and the output is like this:

enter image description here

now the question is how change the output to arabic language?

CodePudding user response:

You should add before moment

moment.locale('ar_SA'); //for Arabia

CodePudding user response:

First I should import the Arabic library

import 'moment/locale/ar'

then

  moment.locale('ar');
  const daysAgo = moment(post.createdAt);

And then return it

    <span>
      {daysAgo.fromNow()}
    </span>
  • Related