date-format-library
v1.1.1
Published
date-format-library simplifies date and time formatting in JavaScript, making it effortless to customize date displays for your web applications and projects.
Downloads
1
Readme
date-format-library
The date-format-library
is a JavaScript library that simplifies date and time formatting, making it effortless to customize date displays for your web applications and projects.
Installation
You can install this library using npm:
npm install date-format-library
Basic Usage
Import the library in your JavaScript code:
import DateFormat from 'date-format-library
DateFormat library supports the following date formats:
| Format |
| :------------- |
| Today
|
| Tomorrow
|
| Next 7 days
|
| Next 30 days
|
| Yesterday
|
| Last 7 days
|
| Last 30 days
|
Example using "Today" date format (you can use any of the mentioned formats 👆):
- -------------------- output;
DateFormat("Today", "dayOfMonth"); // 24
DateFormat("Today", "month"); // 10
DateFormat("Today", "year"); // 2023
DateFormat("Today", "dayOfWeek"); // Tuesday
DateFormat("Today", "shortDate"); // Oct 24
DateFormat("Today", "fullDate"); // 2023-10-24
DateFormat("Today", "fullDateTime"); // Tuesday, October 24, 2023 at 5:30 AM
DateFormat("Today", "localDate"); // Tue Oct 24 2023 18:02:11 GMT+0530 (India Standard Time)
Advanced Usage
To get all date formats as a single object, use the "dateObject" parameter
DateFormat("Today", "YYY-MM-DD", "dateObject")
output:
{
"id": 1,
"fullDate": "2023-10-24",
"label": "Today",
"shortDate": "Oct 24",
"dayOfMonth": 24,
"year": 2023,
"month": 10,
"dayOfWeek": "Tuesday",
"fullDateTime": "Tuesday, October 24, 2023 at 5:30 AM",
"localDate": "2023-10-24T12:32:11.454Z",
"utc": "2023-10-24T12:32:11.454Z",
"longTime": "18:02:11"
}
Custom Date Formats
You can create custom date formats using hyphens
All format options:
| YYY-MM-DD
|
| "YYY-DD-MM
|
| DD-MM-YYY
|
| MM-DD-YYY
|
- -------------------- output;
DateFormat("Today", "YYY-MM-DD"); // 2023-10-24
DateFormat("Tomorrow", "YYY-DD-MM"); // 2023-25-10
DateFormat("Next 7 days", "DD-MM-YYY"); // 31-10-2023
DateFormat("Yesterday", "MM-DD-YYY"); // 10-23-2023
You can create custom date formats using slashes:
All format options:
| YYY-MM-DD
|
| "YYY-DD-MM
|
| DD-MM-YYY
|
| MM-DD-YYY
|
output;
DateFormat("Today", "YYY/MM/DD"); // 2023/10/24
DateFormat("Yesterday", "YYY/DD/MM"); // 2023/23/10
DateFormat("Last 7 days", "DD/MM/YYY"); // 17/10/2023
DateFormat("Last 30 days", "MM/DD/YYY"); // 09/24/20233
Advanced Options
You can also retrieve date formats as date objects:
DateFormat("Today", "YYY-MM-DD", "dateObject")
DateFormat("Tomorrow", "YYY-MM-DD", "dateObject")
DateFormat("Next 7 days", "YYY-MM-DD", "dateObject")
DateFormat("Next 30 days", "YYY-MM-DD", "dateObject")
DateFormat("Yesterday", "YYY-MM-DD", "dateObject")
DateFormat("Last 7 days", "YYY-MM-DD", "dateObject")
DateFormat("Last 30 days", "YYY-MM-DD", "dateObject")
// Sample output
{
"id": 1,
"fullDate": "2023-10-24",
"label": "Today",
"shortDate": "Oct 24",
"dayOfMonth": 24,
"year": 2023,
"month": 10,
"dayOfWeek": "Tuesday",
"fullDateTime": "Tuesday, October 24, 2023 at 5:30 AM",
"localDate": "2023-10-24T12:32:11.454Z",
"utc": "2023-10-24T12:32:11.454Z",
"longTime": "18:02:11"
}
New Advanced Options
you can recive array of object for all the possible days
| Format |
| :------------- |
| Today
|
| Tomorrow
|
| Next 7 days
|
| Next 30 days
|
| Yesterday
|
| Last 7 days
|
| Last 30 days
|
DateFormat("AllDays", "YYY-MM-DD")
DateFormat("AllDays", "YYY/MM/DD")
// Sample output
[{
"id": 1,
"fullDate": "2023-10-24",
"label": "Today",
"shortDate": "Oct 24",
"dayOfMonth": 24,
"year": 2023,
"month": 10,
"dayOfWeek": "Tuesday",
"fullDateTime": "Tuesday, October 24, 2023 at 5:30 AM",
"localDate": "2023-10-24T12:32:11.454Z",
"utc": "2023-10-24T12:32:11.454Z",
"longTime": "18:02:11"
},
you will get balance option object list also....
]
Promises
We're currently working on an update for this package. Stay tuned for upcoming improvements and exciting new features! Your ongoing support is greatly appreciated.