
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
format-your-date
Advanced tools
format-your-date is a lightweight and flexible Node.js package for formatting JavaScript Date objects into various customizable date formats. Whether you need a simple date format or a more complex one with full month names, this package has you covered.
Install the package via npm:
npm install format-your-date
import { DateFormatter } from 'format-your-date';
You can easily format a Date object into various formats as shown below.
const date = new Date();
console.log(DateFormatter.formatDate(date, 'dd-mm-yyyy')); // Output: 24-08-2024
console.log(DateFormatter.formatDate(date, 'fullDate')); // Output: Saturday, 24 August 2024
You can use a custom separator (like . or /) between the date components.
console.log(DateFormatter.formatWithCustomSeparator(date, '/', 'dd-mm-yyyy')); // Output: 24/08/2024
console.log(DateFormatter.formatWithCustomSeparator(date, '.', 'yyyy-mm-dd')); // Output: 2024.08.24
The package supports a variety of date formats, allowing flexibility in how you want your date to be displayed:
| Format | Example Output |
|---|---|
dd-mm-yyyy | 24-08-2024 |
mm-dd-yyyy | 08-24-2024 |
yyyy-mm-dd | 2024-08-24 |
dd/mm/yyyy | 24/08/2024 |
mm/dd/yyyy | 08/24/2024 |
yyyy/mm/dd | 2024/08/24 |
fullDate | Saturday, 24 August 2024 |
dd-mmm-yyyy | 24 Aug, 2024 |
dd-mmmm-yyyy | 24 August, 2024 |
mmm-dd-yyyy | Aug 24, 2024 |
mmmm-dd-yyyy | August 24, 2024 |
In the format string:
dd: Day of the month (2 digits)mm: Month as a number (2 digits)mmm: Month as a short name (e.g., Aug)mmmm: Full month name (e.g., August)yyyy: Full year (e.g., 2024)formatDate(date: Date, format: DateFormat): stringFormats a Date object into the specified format.
Parameters:
date: The JavaScript Date object to be formatted.format: A string representing the desired date format (e.g., dd-mm-yyyy).Returns:
Example:
const date = new Date();
// Basic formats
console.log(DateFormatter.formatDate(date, 'dd-mm-yyyy')); // Output: 24-08-2024
console.log(DateFormatter.formatDate(date, 'mm-dd-yyyy')); // Output: 08-24-2024
console.log(DateFormatter.formatDate(date, 'yyyy-mm-dd')); // Output: 2024-08-24
// Full date
console.log(DateFormatter.formatDate(date, 'fullDate')); // Output: Saturday, 24 August 2024
// Month names
console.log(DateFormatter.formatDate(date, 'dd-mmm-yyyy')); // Output: 24 Aug, 2024
console.log(DateFormatter.formatDate(date, 'dd-mmmm-yyyy')); // Output: 24 August, 2024
console.log(DateFormatter.formatDate(date, 'mmmm-dd-yyyy')); // Output: August 24, 2024
console.log(DateFormatter.formatDate(date, 'mmm-dd-yyyy')); // Output: Aug 24, 2024
// ISO and timestamp
console.log(DateFormatter.formatToISO(date)); // Output: 2024-08-24T00:00:00.000Z
console.log(DateFormatter.formatToTimestamp(date)); // Output: 1692844800000 (example)
const customSeparatorDate = new DateFormatter();
console.log(customSeparatorDate.formatWithCustomSeparator(date, '/', 'dd/mm/yyyy')); // Output: 24/08/2024
// Time formats
console.log(DateFormatter.formatToTime(date, '24-hour')); // Output: 00:00
console.log(DateFormatter.formatToTime(date, '12-hour')); // Output: 12:00 AM
// Relative time
console.log(DateFormatter.formatToRelativeTime(new Date(new Date().getTime() - 3600000))); // Output: 1 hour ago
// Parsing date
console.log(DateFormatter.parseDate('24-08-2024', 'dd-mm-yyyy')); // Output: Sat Aug 24 2024 ...
// Human-readable time
console.log(DateFormatter.formatToHumanReadable(new Date())); // Output: today
// Utility functions
console.log(DateFormatter.isValidDate(new Date())); // Output: true
console.log(DateFormatter.isLeapYear(2024)); // Output: true
console.log(DateFormatter.daysInMonth(2024, 1)); // Output: 29
console.log(DateFormatter.weekNumber(new Date())); // Output: 34 (example)
To contribute or modify the package, follow these steps:
git clone https://github.com/Anshjatana/format-your-date.git
npm install
npm run build
This will generate the files in the dist/ folder.
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, feel free to open an issue or create a pull request. GitHub Repo: Repository
👤 Ansh Jatana
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A simple date formatting package providing a variety of date formats.
We found that format-your-date demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.