lkt-date-tools
v1.0.4
Published
A collection of functions for working with dates
Downloads
73
Maintainers
Readme
LKT Date Tools
Functions
isDate
Checks if a given var is a Date obj
| Arg | Type | Default | Description | |-------------|------|---------|----------------| | target | any | | Var to check |
Usage
import {isDate} from "lkt-date-tools";
isDate(new Date()); // Returns true
isDate('date'); // Returns false
isoToDate
Converts a ISO formatted date to a Date object
| Arg | Type | Default | Description | |--------|--------|---------|-------------------| | str | string | | String to convert |
Usage
import {isoToDate} from "lkt-date-tools";
const date = isoToDate('2020-04-23T00:00:00');
ymdToDate
Converts a 'Y-m-d' formatted date to a Date object
| Arg | Type | Default | Description | |--------|--------|---------|-------------------| | str | string | | String to convert |
Usage
import {ymdToDate} from "lkt-date-tools";
const date = ymdToDate('2020-04-23');
time
Returns current time (in seconds)
Usage
import {time} from "lkt-date-tools";
const stamp = time();
timeInMilliseconds
Returns current time (in milliseconds)
Usage
import {timeInMilliseconds} from "lkt-date-tools";
const stamp = timeInMilliseconds();
getStampInMilliseconds
Returns current timestamp in milliseconds
Usage
import {getStampInMilliseconds} from "lkt-date-tools";
const stamp = getStampInMilliseconds();
getOneYearInSeconds
Returns the seconds in one year
Usage
import {getOneYearInSeconds} from "lkt-date-tools";
const stamp = getOneYearInSeconds();
secondsToMilliseconds
Converts from seconds to milliseconds
| Arg | Type | Default | Description | |---------|--------|---------|--------------------| | seconds | number | | Seconds to convert |
Usage
import {secondsToMilliseconds} from "lkt-date-tools";
const stamp = secondsToMilliseconds();
dateToTimestamp
Converts a Date object to an unix timestamp
| Arg | Type | Default | Description | |------|------|---------|-----------------| | date | Date | | Date to convert |
Usage
import {dateToTimestamp} from "lkt-date-tools";
const stamp = dateToTimestamp(new Date());