Get utc offset from timezone in Javascript

It has become possible nowaday with Intl API: The implementation of Intl is based on icu4c. If you dig the source code, you’ll find that timezone name differs per locale, for example: for (const locale of [“ja”, “en”, “fr”]) { const timeZoneName = Intl.DateTimeFormat(locale, { timeZoneName: “short”, timeZone: “Asia/Tokyo”, }) .formatToParts() .find((i) => i.type === … Read more

Work with a time span in Javascript

Sounds like you need moment.js e.g. moment().subtract(‘days’, 6).calendar(); => last Sunday at 8:23 PM moment().startOf(‘hour’).fromNow(); => 26 minutes ago Edit: Pure JS date diff calculation: var date1 = new Date(“7/Nov/2012 20:30:00”); var date2 = new Date(“20/Nov/2012 19:15:00”); var diff = date2.getTime() – date1.getTime(); var days = Math.floor(diff / (1000 * 60 * 60 * 24)); … Read more

tech