Using Intl.RelativeTimeFormat for Localized Relative Timings #19
Replies: 2 comments 1 reply
-
I do love Intl, I have leveraged it quite a bit recently for locale specific numeric formatting. Admittedly, I have not used the date/time formatting. When I want to continually update times on an item i will generally set a const showtime = () => {
let displays = [... document.querySelectorAll('[data-ts]')]
displays.forEach(ele => {
ele.textContent = new moment.unix(ele.dataset.ts).fromNow()
ele.title = new moment.unix(ele.dataset.ts).local().format('dddd, MMMM Do YYYY, h:mm:ss a')
})
ts_interval = window.setInterval(() => {
let displays = [... document.querySelectorAll('[data-ts]')]
displays.forEach(ele => {
ele.textContent = new moment.unix(ele.dataset.ts).fromNow()
})
}, 60000)
} Might be fun to see if I can get the same thing working with Intl |
Beta Was this translation helpful? Give feedback.
1 reply
-
Wonderful ! That's basically what I did, some time ago: Please submit PR if you see how to improve it ! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Using Intl.RelativeTimeFormat for Localized Relative Timings
A look at how to format relative times in JavaScript
https://www.raymondcamden.com/2024/03/07/using-intlrelativetimeformat-for-localized-relative-timings
Beta Was this translation helpful? Give feedback.
All reactions