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?
CodePudding user response:
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 :)