/
๐Ÿ“

Datetime

jstimeluxonmoment
On this page
  • UTC Now
  • Timezone

Playground

  • Luxon: A powerful, immutable, and friendly wrapper for Javascript dates and times.
  • Moment: Parse, validate, manipulate, and display dates in javascript.
  • Luxon For Moment users

UTC Now

js
const nativeUtcNow = new Date().toISOString();
const luxonUtcNow = DateTime.utc().toISO();
const momentUtcNow = moment().toISOString();

Timezone

  • Convert local time to utc given a timezone
json
const zone = "America/Chicago"
const datetime = "2019-07-09T18:45"
// luxon
DateTime.fromISO(datetime, { zone })
.toUTC()
.toISO()
// moment
moment.tz(datetime, zone).utc().toISOString();
Edit this page
logo
Code-related notes and snippets