Last active
May 26, 2019 12:27
-
-
Save jkasaudhan/6bc49513286eda30aedfd40f0fadbd42 to your computer and use it in GitHub Desktop.
Browser's internationalization api RelativeTimeFormat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For english version - it can be applied to second, minute, | |
// day, week, hour, month and quarter | |
const rtf = new Intl.RelativeTimeFormat('en'); | |
rtf.format(2, 'day') | |
// in 2 days | |
rtf.format(-2, 'day') | |
// two days ago | |
rtf.format(-12, 'minute') | |
// 12 minutes ago | |
rtf.format(12, 'minute') | |
// in 12 minutes | |
// For german version | |
const rtfde = new Intl.RelativeTimeFormat('de'); | |
rtfde.format(2, 'day') | |
// in 2 Tagen | |
rtfde.format(-2, 'day') | |
// vor 2 Tagen | |
rtfde.format(-12, 'minute') | |
// vor 12 Minuten | |
rtfde.format(12, 'minute') | |
// in 12 Minuten | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment