0.0.1 • Published 7 years ago

date-components v0.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

date-components Build Status

Extract individual date components from a Date String.

Install

$ npm install --save date-components

Usage

const dateComponents = require('date-components');

const dateString = 'Mon Feb 13 2017 13:37:38:09 GMT+0000 (WET)';
const components = dateComponents(dateString);

Running console.log(components) from the above code sample would result in:

{
  day: 13,
  weekday: 1,
  month: 1,
  year: 2017,
  hour: 13,
  minutes: 37,
  seconds: 38,
  milliseconds: 9,
  epoch: 1486993058009,
  dateString: 'Mon Feb 13 2017 13:37:38:09 GMT+0000 (WET)'
}

API

dateComponents(input)

input

Type: string

Returns an object with the following keys:

KeyDescription
dayThe day of the month (from 1-31)
weekdayThe day of the week (from 0-6)
monthThe month (from 0-11)
yearThe full year
hourThe hour (from 0-23)
minutesThe minutes (from 0-59)
secondsThe seconds (from 0-59)
millisecondsThe milliseconds (from 0-999)
epochReturns the number of milliseconds since midnight Jan 1 1970, and a specified date
dateStringThe original dateString value you passed to the function

License

MIT © Michael Wuergler