Skip to main content

@std/datetime@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function parse
parse(
dateString: string,
formatString: string
): Date

Takes an input string and a formatString to parse to a date.

The following symbols from unicode LDML are supported:

  • yyyy - numeric year.

  • yy - 2-digit year.

  • M - numeric month.

  • MM - 2-digit month.

  • d - numeric day.

  • dd - 2-digit day.

  • H - numeric hour (0-23 hours).

  • HH - 2-digit hour (00-23 hours).

  • h - numeric hour (1-12 hours).

  • hh - 2-digit hour (01-12 hours).

  • m - numeric minute.

  • mm - 2-digit minute.

  • s - numeric second.

  • ss - 2-digit second.

  • S - 1-digit fractionalSecond.

  • SS - 2-digit fractionalSecond.

  • SSS - 3-digit fractionalSecond.

  • a - dayPeriod, either AM or PM.

  • 'foo' - quoted literal.

  • ./- - unquoted literal.

Examples

Example 1

import { parse } from "@std/datetime/parse";

parse("20-01-2019", "dd-MM-yyyy"); // output : new Date(2019, 0, 20)
parse("2019-01-20", "yyyy-MM-dd"); // output : new Date(2019, 0, 20)
parse("20.01.2019", "dd.MM.yyyy"); // output : new Date(2019, 0, 20)
parse("01-20-2019 16:34", "MM-dd-yyyy HH:mm"); // output : new Date(2019, 0, 20, 16, 34)
parse("01-20-2019 04:34 PM", "MM-dd-yyyy hh:mm a"); // output : new Date(2019, 0, 20, 16, 34)
parse("16:34 01-20-2019", "HH:mm MM-dd-yyyy"); // output : new Date(2019, 0, 20, 16, 34)
parse("01-20-2019 16:34:23.123", "MM-dd-yyyy HH:mm:ss.SSS"); // output : new Date(2019, 0, 20, 16, 34, 23, 123)

Parameters

dateString: string

Date string

formatString: string

Format string

Return Type

Parsed date

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/datetime

Import symbol

import { parse } from "@std/datetime";
or

Import directly with a jsr specifier

import { parse } from "jsr:@std/datetime";