simple-date-pattern
v1.0.6
Published
A simple way of dealing with dates
Downloads
3
Maintainers
Readme
Simple-Date-Pattern
Date Format Function
This TypeScript module exports a function called formatDate
. This function is used to format a JavaScript Date
object into a string based on a provided format string.
Locale is used to determine the language for month and day names.
Parameters
date (Date): The date to format.
format (string): The format string to use. Defaults to 'yyyy-mm-dd HH:MM'. The format string can contain the following tokens:
- 'yyyy': 4-digit year
- 'yy': 2-digit year
- 'mmmm': Full month name
- 'mmm': Short month name
- 'mm': 2-digit month number
- 'm': Month number
- 'dddd': Full weekday name
- 'ddd': Short weekday name
- 'dd': 2-digit day of the month
- 'd': Day of the month
- 'HH': 2-digit hour (24-hour format)
- 'H': Hour (24-hour format)
- 'hh': 2-digit hour (12-hour format)
- 'h': Hour (12-hour format)
- 'MM': 2-digit minute
- 'M': Minute
- 'SS': 2-digit second
- 'S': Second
- 'A': AM/PM indicator
locale (string): The locale to use when formatting date parts. Defaults to the user's current language.
Returns
- string: The formatted date string.
Usage
const date = new Date();
const formattedDate = formatDate(date, 'yyyy-mm-dd HH:MM');
console.log(formattedDate); // Outputs: 2022-01-01 12:00