An open API service indexing awesome lists of open source software.

https://github.com/arshadkazmi42/custom-date-formatting

:calendar: Npm package for custom date formatting
https://github.com/arshadkazmi42/custom-date-formatting

date-formatting dates format-date formatting moment

Last synced: 3 days ago
JSON representation

:calendar: Npm package for custom date formatting

Awesome Lists containing this project

README

        

# Custom Date Formatting
[![Build Badge](https://api.travis-ci.org/arshadkazmi42/custom-date-formatting.svg?branch=master)](https://travis-ci.org/arshadkazmi42/custom-date-formatting)
[![npm Downloads](https://img.shields.io/npm/dt/customdateformating.svg)](https://www.npmjs.com/package/customdateformating)
[![Package Size](https://img.shields.io/bundlephobia/min/customdateformating.svg)](https://www.npmjs.com/package/customdateformating)
[![NPM Version](https://img.shields.io/npm/v/customdateformating.svg)](https://www.npmjs.com/package/customdateformating)
[![Contributors](https://img.shields.io/github/contributors/arshadkazmi42/custom-date-formatting.svg)](https://github.com/arshadkazmi42/custom-date-formatting/graphs/contributors)
[![Commit](https://img.shields.io/github/last-commit/arshadkazmi42/custom-date-formatting.svg)](https://github.com/arshadkazmi42/custom-date-formatting/commits/master)

## How to install?
[![NPM](https://nodei.co/npm/customdateformating.png)](https://www.npmjs.com/package/customdateformating/)

## Usage

### 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.

```javascript
// 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.

```javascript
// 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.

```javascript
// 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"
```

### Custom Source Format date custom new format
Pass the date (input date), currentFormat (input date format), newformat. (required date format)to the Function.

```javascript
// 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.

```javascript
// 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");

// Output: 1503858600000
```

## Contributors

Thank you to all the contributors who have helped us in making this project better 🙌

## Contributing Guidelines
Read the contributing guidelines [here](CONTRIBUTING.md)