Skip to main content
Home
This release is 12 versions behind 0.225.6 — the latest version of @std/datetime. Jump to latest

@std/datetime@0.224.0
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads4,217/wk
Published2 years ago (0.224.0)

UNSTABLE: Utilities for dealing with Date objects

function parse
parse(
dateString: string,
formatString: string,
): Date

Parses a date string using the specified format string.

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 fractional second
  • SS - 2-digit fractional second
  • SSS - 3-digit fractional second
  • a - dayPeriod, either AM or PM
  • 'foo' - quoted literal
  • ./- - unquoted literal

Examples

Basic usage

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

parse("20-01-2019", "dd-MM-yyyy"); // 2019-01-19T13:00:00.000Z

parse("01-20-2019 04:34 PM", "MM-dd-yyyy hh:mm a"); // 2019-01-20T05:34:00.000Z

parse("01-20-2019 16:34:23.123", "MM-dd-yyyy HH:mm:ss.SSS"); // 2019-01-20T05:34:23.123Z

Parameters

dateString: string

The date string to parse.

formatString: string

The date time string format.

Return Type

The 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";

Add Package

pnpm i jsr:@std/datetime
or (using pnpm 10.8 or older)
pnpm dlx jsr add @std/datetime

Import symbol

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

Add Package

yarn add jsr:@std/datetime
or (using Yarn 4.8 or older)
yarn dlx jsr add @std/datetime

Import symbol

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

Add Package

vlt install jsr:@std/datetime

Import symbol

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

Add Package

npx jsr add @std/datetime

Import symbol

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

Add Package

bunx jsr add @std/datetime

Import symbol

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