Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno_nest/example/dev/deps.ts>format

Refer to nestjs to realize some common functions for Deno, support hono and oak
Go to Latest
function format
import { format } from "https://deno.land/x/deno_nest@v3.5.1/example/dev/deps.ts";

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

Examples

Example 1

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

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

Parameters

date: Date

Date

formatString: string

Format string

Returns

string

formatted date string