Reformat a string date in UTC to a new format.

an error if the input format is invalid, or a date-fns RangeError if the format is invalid.

const dateString = '2024-08-19T00:00:00.000+00:00';
const newFormat = 'yyyy-MM-dd';
reformatUtcDateString(dateString, newFormat); // '2024-08-19'
  • Parameters

    • dateString: string

      must be a valid date string in ISO 8601 format, that has date, time and UTC offset. For example, 2024-08-19T00:00:00.000+00:00 or 2024-08-19T10:30:00Z

    • newFormat: string

      any accepted date-fns format string. https://date-fns.org/v1.29.0/docs/format

    Returns string

    the reformatted date string in UTC