Skip to content

Instantly share code, notes, and snippets.

@smpnjn
Created December 11, 2020 13:37
Show Gist options
  • Save smpnjn/439c52e92e3366854c0ba4011389ac14 to your computer and use it in GitHub Desktop.
Save smpnjn/439c52e92e3366854c0ba4011389ac14 to your computer and use it in GitHub Desktop.
const currentUnix = Temporal.now.instant() // get current unix time
const timezoneUnix = Temporal.now.timeZone() // get current unix time for current time zone
// It is easy to add or subtract() from a Temporal object
const modifyUnix = currentUnix.add({ "day" : 1 }); // Add one day to 'currentUnix'
zdt = Temporal.ZonedDateTime.from('1995-12-07T03:24-08:00[America/Los_Angeles]');
['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'][zdt.dayOfWeek - 1]; // => THU
// toLocaleString still works as well
const newDate = Temporal.PlainDate.from('2020-12-11');
newDate.toLocaleString(); // => example output: 12/11/2020
newDate.toLocaleString('de-DE'); // => example output: 11.12.2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment