Skip to content

Latest commit

 

History

History
67 lines (56 loc) · 4.48 KB

README.md

File metadata and controls

67 lines (56 loc) · 4.48 KB

Custom Date Formatting

npm version Dependencies npm Downloads

How to install?

NPM

Small package which provides some basic functions for custom date formatting

Custom Format date with Days (+/-)

Pass the format of the date required and numberOfDays to add from current day to the Function.
For previous days numberOfDays should be passed as negative value.

// Create Instance of the DateValidator
const DateFormatting = require('custom-date-formatting');
// This will return a string with new date
DateFormatting.getNextOrPrevDateCustomFormat("YYYY-MM-DD", 0);
Output: "2018-10-06"

Custom Format date with Minutes (+/-)

Pass the format of date required and minutesToAdd to add/subtract minutes from current time to the Function.
For passed minute of time, minutesToAdd should be passed as negative value.

// Create Instance of the DateValidator
const DateFormatting = require('custom-date-formatting');
// This will return a string with new date and time
DateFormatting.getNextOrPrevMinuteDateCustomFormat("YYYY-MM-DD HH:mm", 1);
// Output: "2018-10-06 00:39"

Custom Format date with Seconds (+/-)

Pass the format of date required and secondsToAdd to add/subtract seconds from current time.
For passed minute of time, secondsToAdd should be passed as negative value.

// Create Instance of the DateValidator
const DateFormatting = require('custom-date-formatting');
// This will return a string with new date and time
DateFormatting.getNextOrPrevSecondDateCustomFormat("YYYY-MM-DD HH:mm:ss", 10);

Output: "2018-10-06 00:40:02"

customSourceDateFormatToCustomNewDateFormat

Pass the date (input date), currentFormat (input date format), newformat. (required date format)to the Function.

// Create Instance of the DateValidator
const DateFormatting = require('custom-date-formatting');
// This will return a string with date in new format
DateFormatting.customSourceDateFormatToCustomNewDateFormat("2017-08-28 23:22:00", "YYYY-MM-DD HH:mm:ss", "dddd DD MMM YYYY");
// Output: "Monday 28 Aug 2017"

Timestamp from custom date format

Pass the date (input date), currentFormat (input date format)to the function.

// Create Instance of the DateValidator
const DateFormatting = require('customdateformatting');
//This will return input date value as timestamp in milliseconds.
DateFormatting.getTimeStampFromCurrentDateFormat("28 Aug 2017", "DD MMM YYYY");

Contributors


Contributing Guidelines

Read the contributing guidelines here