Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active November 16, 2017 11:02
Show Gist options
  • Save daliborgogic/6d7553f99af1ee3382a26a67e752db56 to your computer and use it in GitHub Desktop.
Save daliborgogic/6d7553f99af1ee3382a26a67e752db56 to your computer and use it in GitHub Desktop.
function daysInMonth (date = new Date()) {
  const m = new Date(date)
  return new Date(m.getFullYear(), m.getMonth() + 1, 0).getDate()
}

daysInMonth()
> 30
daysInMonth('Wed, 15 Feb 2017 22:11:32 GMT')
> 28

// Timezone difference between UTC time and local time, in minutes
const newDate = new Date()
const tzOffset = newDate.getTimezoneOffset()

tzOffset
> -60 // UTC+01:00

const tzOffsetInMs = utc => { return -(1000 * 60 * utc) }

tzOffsetInMs(tzOffset)
> 3600000 //ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment