Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/hex/src/lib/stdx/mod.ts>datetime.parse

An ecosystem delivering practices, philosophy and portability. Powered By Deno and JavaScript.
Latest
function datetime.parse
import { datetime } from "https://deno.land/x/hex@0.6.5/src/lib/stdx/mod.ts";
const { parse } = datetime;

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

Examples

Example 1

import { parse } from "https://deno.land/std@0.224.0/datetime/mod.ts";

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

Returns

Parsed date