Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How i can turn datetime to like "one minute age" in prisma node js graphql?

I’m trying to set the date time in Prisma migrate to human like one minute age, one month ago how I can manage to do it?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the Internationalization API Intl to do just that.

It would look something like:

const formatter = new Intl.RelativeTimeFormat('en') // specify language here
console.log(formatter.format(-5, 'minutes')) // 5 minutes ago
console.log(formatter.format(5, 'months')) // in 5 months

Note that you need to specify the amount of time in English but if you change the language of the formatter, it will adapt the output to the specified language.

Of course you first need to calculate the amount of time first, but that shouldn’t be difficult 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading