Skip to content

Instantly share code, notes, and snippets.

@jkeefe
Last active May 12, 2023 19:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkeefe/2dce44f030d0ec149792cb72b5f86306 to your computer and use it in GitHub Desktop.
Save jkeefe/2dce44f030d0ec149792cb72b5f86306 to your computer and use it in GitHub Desktop.
Parse current date to U.S. Eastern time + customize short months & a.m./p.m.
// installation:
// npm install dayjs dayjs-plugin-utc --save
// note: if not already a module, in package.json add "type":"module",
import dayjs from 'dayjs';
import updateLocale from 'dayjs/plugin/updateLocale.js';
import utc from 'dayjs/plugin/utc.js';
import timezone from 'dayjs/plugin/timezone.js';
// set up the as-of date
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault('America/New_York');
dayjs.extend(updateLocale);
dayjs.updateLocale('en', {
monthsShort: [
'Jan.', 'Feb.', 'March', 'April', 'May', 'June',
'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.',
],
meridiem: (hour, minute, isLowercase) => (hour >= 12 ? 'p.m.' : 'a.m.'),
});
let now = dayjs().tz('America/New_York').format('dddd, MMM D [at] h:mm a [Eastern]').replace(':00','')
//// if not using modules ////
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const updateLocale = require('dayjs/plugin/updateLocale.js');
const timezone =require('dayjs/plugin/timezone');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment