@sineverba/date-convert
v2.3.0
Published
Convert a date from / to ISO format YYYYMMDD to human readable format (DD/MM/YYYY)
Downloads
31
Readme
Date Convert
| CI / CD | Status | | ------- | ------ | | NPM | | | Semaphore CI | | | Circle CI | | | Coverall | | | SonarCloud | |
date-convert
converts a ISO format YYYYMMDD string "19820405" to "05/04/1982" (where 05 is day and 04 is April). Use "/"
as separator in output.
It works also with a date with other format. Simply, call the method fromIsoToHuman
.
For example
const newDate = fromIsoToHuman("2024-01-31T15:27:42.427438", "DD/MM/YYYY");
console.log(newDate); // It prints 31/01/2024
Accepted INPUT
| Input | Output | | ----- | -------| | "20220323" | 23/03/2022 | | "2022-03-23" | 23/03/2022 | | "2022-03-09T12:31:16.699904" | 09/03/2022 |
Installation
npm install @sineverba/date-convert
Usage
// Import module
import { fromHumanToIso, fromIsoToHuman } from "@sineverba/date-convert";
// Or
// var {fromIsoToHuman, fromHumanToIso} = require('@sineverba/date-convert');
const humanDate = fromIsoToHuman("20200102");
console.log(humanDate); // returns 02/01/2020
const humanDateWithFormat = fromIsoToHuman("20200102", "YYYY-MM-DD");
console.log(humanDateWithFormat); // returns 2020-01-02
const isoDate = fromHumanToIso("02/01/2020");
console.log(isoDate); // returns 20200102
const isoDateWithFormat = fromHumanToIso("2020-01-02", "YYYY-MM-DD");
console.log(isoDateWithFormat); // returns 20200102
Tests
npm run test
for simple test
npm run coverage
for coverage