1.0.0 • Published 6 years ago

string-to-date v1.0.0

Weekly downloads
10
License
ISC
Repository
github
Last release
6 years ago

About:

Function "stringToDate" parse string. It returns object of Date. If format or date are invalid then it returns null.

Example:

import { stringToDate } from 'string-to-date'

const date = stringToDate('2018-02-13 10:22:35')

console.log(date instanceof Date) //true
console.log(date.getFullYear()) //2018
console.log(date.getMonth()) //1
console.log(date.getDate()) //13
console.log(date.getHours()) //10
console.log(date.getMinutes()) //22
console.log(date.getSeconds()) //35

console.log(stringToDate('qwerty')) //null

Params:

NameTypeDefault
datestring
formatstringYYYY-MM-DD HH:mm:ss