farid-fdate v1.0.1
farid-fdate
This JS library is just a collection of functions for manipulating date and time. It's small, simple, and easy to learn.
Installation
Inside your project folder do:
npm install --save farid-fdate
or, install it globally to use FDate
from the command line.
npm install -g farid-fdate
Usage
NodeJS or ES6/ES7
Require the module farid-fdate
const FDate = require("farid-fdate")
var date = new FDate("2022-12-10 11:20");
Methods
- Get the day.
- Get the name of the day.
- Get the month.
- Get the name of the month.
- Get the year.
- Adding days.
- Removing days.
- Adding months.
- Removing months.
- Adding years.
- Removing years.
Get the diff between date and now string.
- Get the diff between date and now object.
- Formatting date and time objects.
Preview
Examples of FDate
methods:
getDay()
date.getDay(); // => 10
getDayName()
date.getDayName(); // => 'Friday'
getMonth()
date.getMonth(); // => 12
getMonthName()
date.getMonthName(); // => 'December'
getYear()
date.getYear(); // => 2022
addDay(day)
Parameter day by default equalt 1
date.addDay(2); // => from '10/12/2022 11:20' to '12/12/2022 11:20'
removeDay(day)
Parameter day by default equalt 1
date.removeDay(2); // => from '10/12/2022 11:20' to '8/12/2022 11:20'
addMonth(month)
Parameter month by default equalt 1
date.addMonth(2); // => from '10/12/2022 11:20' to '10/2/2023 11:20'
removeMonth(month)
Parameter month by default equalt 1
date.removeMonth(2); // => from '10/12/2022 11:20' to '10/10/2022 11:20'
addYear(year)
Parameter year by default equalt 1
date.addYear(2); // => from '10/12/2022 11:20' to '10/12/2024 11:20'
removeYear(year)
Parameter year by default equalt 1
date.removeYear(2); // => from '10/12/2022 11:20' to '10/12/2020 11:20'
diffForHumain()
date.diffForHumain(); // => '1h 35min 20s 4d 1y'
diffForHumainStructure()
date.diffForHumainStructure(); // => { hours: 15, seconds: 46.389, minutes: 38, days: 0, months: 0, years: 0 }
format()
date.format(now, 'd/m/Y H:i'); // => '10/12/2022 11:20'
Available tokens and their descriptions are as follows: |Token|Description|Output| |-----|-----------|------| |h|12-hour|11| |H|24-hour|23| |i|minute|20| |s|second|30| |l|millisecond|753| |d|day (int)|10| |D|day name (string)|Friday| |m|month (int)|12| |M|month name (string)|December| |y|two digits year|22| |Y|four digits year|2022|
License
Keywords
Date Time DateTime Format Parse Hour Minute Second Day Month Year