string-to-date

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

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
string-to-date
001.0.05 years ago5 years agoMinified + gzip package size for string-to-date in KB

Readme

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:

| Name | Type | Default | | --- | --- | --- | | date | string | | | format | string | YYYY-MM-DD HH:mm:ss |