parseDate

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.datetime

This function allows you to parse a date string. It will returns the Date instance for this date. Under the hood, it make uses of the wonderful Luxon library. Make sure to use the library if you need more control over your dates. Luxon support these date formats:

  • ISO 8601
  • RFC2822
  • HTTP (header)

Params

  1. date*-String

    The date string to parse

  2. settings{}TParseDateSettings

    Some settings to configure your parsing

Return

  1. -Date

    The `Date` instance representing your date string

Example

import { parseDate } from '@blackbyte/sugar/datetime';
parseDate('2025-10-12');
parseDate('2024-10-15T10:30:00Z');

Settings

  1. formatString

    If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See Luxon documentation for the list of supported tokens.