A utility class providing various date formatting and parsing methods in TypeScript.
- Convert a date string to
Date
object withparseDateString
. - Format dates into various string formats, such as ISO, US locale, and more.
- Handle a variety of date string formats for both parsing and formatting.
pnpm add @rightcapital/date-helpers
Convert a date string to a Date object using various possible formats.
import { DateHelpers } from '@rightcapital/date-helpers';
const date = DateHelpers.parseDateString('2023/01/01');
Format a date as an ISO date string.
import { DateHelpers } from '@rightcapital/date-helpers';
const isoDateString = DateHelpers.formatDateLikeToIsoDateString(
new Date(2023, 0, 1),
);
// Result: Sun Jan 01 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
Format a date as a US locale date string.
import { DateHelpers } from '@rightcapital/date-helpers';
const usDateString = DateHelpers.formatDateLikeToUsLocaleDateString(
new Date(2023, 0, 31),
);
// Result: "01/31/2023"
Formats a date as a US locale time string.
import { DateHelpers } from '@rightcapital/date-helpers';
const usDateString = DateHelpers.formatDateLikeToUsLocaleDateTimeString(
'2025/10/20 12:00:00',
);
// Result: "10/20/2025 12:00:00"
Formats a date as a string in the MDY format.
const monthDayYearString = DateHelpers.formatDateLikeToUsLocaleMediumDateString(
new Date(2023, 0, 1),
);
// Result: "Jan 1, 2023"
Here is the API documentation for the modules included in the package.