Skip to content

Instantly share code, notes, and snippets.

@lukethacoder
Last active July 25, 2020 12:02
Show Gist options
  • Save lukethacoder/045559b137a2793d0bbe5f4e31ccdc2a to your computer and use it in GitHub Desktop.
Save lukethacoder/045559b137a2793d0bbe5f4e31ccdc2a to your computer and use it in GitHub Desktop.
JS Dates n Times
let now = new Date()
let yr = now.getFullYear()
let mth = `${
now.getMonth() + 1 < 10 ? `0${now.getMonth() + 1}` : now.getMonth() + 1
}`
let dt = `${date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()}`
let hrs = `${
date.getHours() < 10 ? `0${date.getHours()}` : date.getHours()
}`
let mins = `${
date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes()
}`
const WEEKS_ARRAY = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
]
const dayOfWeek = WEEKS_ARRAY[new Date().getDay()];
console.log(`Today is ${dayOfWeek}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment