1.1.0 • Published 6 years ago

date2obj v1.1.0

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

date2obj

Build Status npm version npm Greenkeeper badge

Parse Date to Simple Object in JavaScript

:collision: Zero dependencies

Usage

npm i date2obj --save
date2obj() // Get current time
date2obj(new Date()) // Equal to the first one
date2obj(new Date(1518545575000)) // Put Date object in the function to get that time
const date2obj = require('date2obj');

const currentTime = date2obj();
console.log(currentTime);
// Local time
// {
//   year: 'YYYY',
//   month: 'MM',
//   day: 'DD',
//   hour: 'HH',
//   minute: 'mm',
//   second: 'SS'
// }

const otherTime = date2obj(new Date(1518545575000));
console.log(otherTime);
// Local time with the epoch
// {
//   year: "2018",
//   month: "02",
//   day: "14",
//   hour: "02",
//   minute: "12",
//   second: "55"
// }

Configuration Options

usage with options

date2obj(dateObject [, options])

fields

default: ['year', 'month', 'day', 'hour', 'minute', 'second']

usage example:

const otherTime = date2obj(new Date(1518545575000), {
  fields: ['hour', 'minute', 'second']
});
console.log(otherTime);
// Local time with the epoch
// {
//   hour: "02",
//   minute: "12",
//   second: "55"
// }

License

MIT

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago