0.0.2 • Published 12 months ago

advanced-date-formatter v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

Advanced Date Formatter

advanced-date-formatter is a simple utility for formatting dates in various common formats. This package provides an easy way to convert JavaScript Date objects to formatted date strings using customizable format strings.

Features

  • Format dates in various formats such as YYYY-MM-DD, MM/DD/YYYY, YYYY-MM-DD hh:mm:ss
  • Supports placeholders for year, month, day, hours, minutes, and seconds
  • Works with UTC time to avoid time zone issues

Installation

To install the package, use npm:

npm install advanced-date-formatter

const formatDate = require('advanced-date-formatter');
Usage

Import the formatDate function from the package and use it to format Date objects according to your needs.
Importing the Package

javascript

const formatDate = require('advanced-date-formatter');

Formatting Dates

1. Format to YYYY-MM-DD:

javascript

const date = new Date();
console.log(formatDate(date, 'YYYY-MM-DD')); // Example output: 2024-07-26

2. Format to MM/DD/YYYY:

javascript

const date = new Date();
console.log(formatDate(date, 'MM/DD/YYYY')); // Example output: 07/26/2024

3. Format to YYYY-MM-DD hh:mm:ss:

javascript

const date = new Date();
console.log(formatDate(date, 'YYYY-MM-DD hh:mm:ss')); // Example output: 2024-07-26 14:30:45

4. Format with Single Digit Hour:

javascript

const date = new Date(Date.UTC(2024, 6, 26, 1, 30, 45)); // Month is 0-indexed
console.log(formatDate(date, 'YYYY-MM-DD hh:mm:ss')); // Example output: 2024-07-26 01:30:45

API
formatDate(date, format)

Formats a Date object according to the specified format string.

    Parameters:
        date (Date): The date to format.
        format (string): The format string with placeholders.

    Returns:
        (string): The formatted date string.

Placeholders:

    YYYY: Year (e.g., 2024)
    MM: Month (e.g., 07)
    DD: Day of the month (e.g., 26)
    hh: Hours (24-hour format, e.g., 14)
    mm: Minutes (e.g., 30)
    ss: Seconds (e.g., 45)

Development

To test the package, use:

bash

npm test

This will run the test cases and verify that the package functions correctly.
Contributing

Feel free to contribute to the project by opening issues or pull requests. Make sure to follow the coding standards and write tests for new features.
License

MIT License. See the LICENSE file for details.

Author
karuppusamy.p


### Notes:

1. **Customizable Formats**: This README provides examples of how to use the package to format dates in different formats.
2. **API Documentation**: It describes the `formatDate` function and the placeholders available.
3. **Development and Contribution**: Includes instructions for testing and contributing to the project.
4. **License and Author**: Make sure to update the license and author information as needed.

Feel free to adjust any sections or add more details as needed. Let me know if there are other aspects you'd like to include!
0.0.2

12 months ago

0.0.1

12 months ago

1.0.0

12 months ago