0

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?

sultan.h
  • 331
  • 1
  • 4
  • 16
  • check this https://momentjs.com/docs/#/i18n/ also this should answer your question https://stackoverflow.com/questions/17493309/how-do-i-change-the-language-of-moment-js – buzz Nov 17 '22 at 06:45

2 Answers2

1

You should add before moment

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

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>
sultan.h
  • 331
  • 1
  • 4
  • 16