Last active
May 12, 2023 19:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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