Skip to content

Instantly share code, notes, and snippets.

@SarathSantoshDamaraju
Last active November 13, 2019 12:07
Show Gist options
  • Select an option

  • Save SarathSantoshDamaraju/b4ccb12c09d64b4344153d4580351b39 to your computer and use it in GitHub Desktop.

Select an option

Save SarathSantoshDamaraju/b4ccb12c09d64b4344153d4580351b39 to your computer and use it in GitHub Desktop.
Intl() gist #1
'use strict;'
let timeDiff = Math.ceil((new Date('2019-11-12T11:38:02.787Z') - new Date())/86400000);
/*
86400000 is to convert the time to days.
1000 to convert it into seconds
1000*60 to convert it into minutes
1000*60*60 to convert it into Hours
*/
const localTimeString = new Intl.RelativeTimeFormat('en', { numeric: 'auto'});
localTimeString.format(timeDiff, 'days'); // Prints yesterday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment