Skip to content

Instantly share code, notes, and snippets.

@shisama
Last active April 23, 2019 18:23
Show Gist options
  • Save shisama/d50271634a4e76c7d8909109411170f2 to your computer and use it in GitHub Desktop.
Save shisama/d50271634a4e76c7d8909109411170f2 to your computer and use it in GitHub Desktop.
Intl.RelativeTimeFormat - New JavaScript Features in Node.js v12
var rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' });
console.log(rtf1.format(3, 'quarter'));
//expected output: "in 3 qtrs."
console.log(rtf1.format(-1, 'day'));
//expected output: "1 day ago"
var rtf2 = new Intl.RelativeTimeFormat('ja', { numeric: 'auto' });
console.log(rtf2.format(2, 'day'));
//expected output: "明後日"
var rtf3 = new Intl.RelativeTimeFormat('en', { style: 'narrow', numeric: 'auto' });
console.log(rtf3.format(1, 'day'));
//expected output: "tommorow"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment