0.0.1-2 • Published 4 years ago

@missthee/datetool v0.0.1-2

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

date-tool

Overview

An open source simple JavaScript Date library for formatting and processing.

Getting Started

install by npm

npm i @missthee/datetool

use

import { dateToString, addDay, DateHepler } from "@missthee/datetool";
let date = new Date('2000/01/01');
//formatting
console.log(dateToString(date, 'yyyy-MM-dd')); // 2000-01-01
//processing
//NOTICE: All calculation operations will change the incoming Date object
let result = addDay(date, 1); 
console.log(result); // 2000-01-02
console.log(date);   // 2000-01-02

Example

import {DateHelper, dateToStringFactory, dateToString, getFullDayInMonth, isLeapYear, addMillisecond, addSecond, addMinute, addHour, addDay, addMonth, addYear,} from "@missthee/datetool";
let date = new Date('2000-01-01');

//formatting
dateToString(date, 'yyyyMMdd');     //20000101
let dts = dateToStringFactory('yyyyMMdd');
dts(date);                          //20000101
dts(new Date('2020/11/11'));        //20201111

//processing
//NOTICE: All calculation operations will change the incoming Date object
new DateHelper(date).addDay(1).addMonth(1).addYear(-1).getDate();
addYear(date, 1);
addMonth(date, 1);
addDay(date, 1);
addHour(date, 1);
addMinute(date, 1);
addSecond(date, 1);
addMillisecond(date, 1);

//misc
isLeapYear(2000); //true
getFullDayInMonth(2000, 1); //29

Converting to String

KeyDescriptionValue
yyyyThe year1999 2001
yyThe year's last two-digit number99 01
MMThe month of the year with leading zero01 - 12
MThe month of the year between 1-121 - 12
ddThe day of the month with leading zero01 - 31
dThe day of the month between 1 and 311 - 31
HHThe hour of the day with leading zero00 - 23
HThe hour of the day between 0-230 - 23
hhThe hour of the day with leading zero01 - 12
hThe hour of the day between 1-121 - 12
mmThe minute of the hour with leading zero00 - 59
mThe minute of the hour between 0-590 - 59
ssThe seconds of the minute with leading zero00 - 59
sThe seconds of the minute between 0-590 - 59
SSSThe milliseconds of the second between .000-.999000 - 999
SSThe milliseconds of the second between .00-.9900 - 99
SThe milliseconds of the second between .0-.90 - 9