import * as mod from "https://deno.land/std@0.224.0/datetime/mod.ts";
Utilities for dealing with Date
objects.
Constants
Constants such as SECOND
, MINUTE
and HOUR
can be found in the constants
module.
Day of year
dayOfYear
returns the number of the day in the year in the local
timezone. dayOfYearUtc
does the same but in UTC time.
import { dayOfYear } from "https://deno.land/std@0.224.0/datetime/day_of_year.ts";
dayOfYear(new Date("2019-03-11T03:24:00")); // 70
Difference between dates
difference
calculates the difference of the 2 given dates in
various units.
import { difference } from "https://deno.land/std@0.224.0/datetime/difference.ts";
const date0 = new Date("2018-05-14");
const date1 = new Date("2020-05-13");
difference(date0, date1);
// {
// milliseconds: 63072000000,
// seconds: 63072000,
// minutes: 1051200,
// hours: 17520,
// days: 730,
// weeks: 104,
// months: 23,
// quarters: 7,
// years: 1
// }
Formatting date strings
format
formats a date to a string with the specified format.
import { format } from "https://deno.land/std@0.224.0/datetime/format.ts";
const date = new Date(2019, 0, 20, 16, 34, 23, 123);
format(date, "dd-MM-yyyy"); // "20-01-2019"
format(date, "MM-dd-yyyy HH:mm:ss.SSS"); // "01-20-2019 16:34:23.123"
format(date, "'today:' yyyy-MM-dd"); // "today: 2019-01-20"
Detecting leap years
isLeap
returns whether the given year is a leap year.
isUtcLeap
does the same but in UTC time.
import { isLeap } from "https://deno.land/std@0.224.0/datetime/is_leap.ts";
isLeap(new Date("1970-01-02")); // false
isLeap(1970); // false
isLeap(new Date("1972-01-02")); // true
isLeap(1972); // true
Parsing date strings
parse
parses a date string using the specified format string.
import { parse } from "https://deno.land/std@0.224.0/datetime/parse.ts";
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
Week of year
weekOfYear
returns the number of the week in the year in the local
timezone.
import { weekOfYear } from "https://deno.land/std@0.224.0/datetime/week_of_year.ts";
weekOfYear(new Date("2020-12-28T03:24:00")); // 53
weekOfYear(new Date("2020-07-10T03:24:00")); // 28
Variables
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> v DAY | The number of milliseconds in a day. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> v HOUR | The number of milliseconds in an hour. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | The number of milliseconds in a minute. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | The number of milliseconds in a second. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> v WEEK | The number of milliseconds in a week. |
Functions
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Returns the number of the day in the year in the local time zone. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Returns the number of the day in the year in UTC time. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Calculates the difference of the 2 given dates in various units. If the units are omitted, it returns the difference in the all available units. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Formats a date to a string with the specified format. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Returns whether the given year is a leap year. Passing in a
|
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Returns whether the given year is a leap year in UTC time. This always returns the same value regardless of the local timezone. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Parses a date string using the specified format string. |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Returns the ISO week number of the provided date (1-53). |
Interfaces
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Options for |
Type Aliases
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Return type for |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> | Options for |
*]:space-x-2 [&>*]:min-w-[13rem] [&>*]:flex [&>*]:items-center"> T Unit | Duration units for |