JavaScript Date Snippets

The JavaScript snippet collection contains a wide variety of ES6 helper functions. It includes helpers for dealing with primitives, arrays and objects, as well as algorithms, DOM manipulation functions and Node.js utilities.

  • Format duration

    Returns the human-readable format of the given number of milliseconds.

    JavaScript, Date · Oct 22, 2020

  • How can I implement a sleep function in JavaScript?

    Learn all the different ways you can implement a sleep() function in JavaScript.

    JavaScript, Date · Nov 6, 2021

  • Number of seconds to ISO format

    Returns the ISO format of the given number of seconds.

    JavaScript, Date · Oct 13, 2021

  • Add minutes to date

    Calculates the date of n minutes from the given date, returning its string representation.

    JavaScript, Date · Nov 28, 2020

  • Count weekdays between two dates

    Counts the weekdays between two dates.

    JavaScript, Date · Oct 20, 2020

  • Date range generator

    Creates a generator, that generates all dates in the given range using the given step.

    JavaScript, Date · Jun 21, 2021

  • Check if date is valid

    Checks if a valid date object can be created from the given values.

    JavaScript, Date · Oct 20, 2020

  • Date to ISO format with timezone

    Converts a date to extended ISO format (ISO 8601), including timezone offset.

    JavaScript, Date · Oct 13, 2021

  • Add days to date

    Calculates the date of n days from the given date, returning its string representation.

    JavaScript, Date · Nov 28, 2020

  • Add weekdays to date

    Calculates the date after adding the given number of business days.

    JavaScript, Date · Jan 7, 2021

  • How do I compare two dates in JavaScript?

    Learn how you can compare two dates in JavaScript using various different techniques.

    JavaScript, Date · Jan 16, 2022

  • Day of year

    Gets the day of the year (number in the range 1-366) from a Date object.

    JavaScript, Date · Oct 19, 2020

  • Get colon time from date

    Returns a string of the form HH:MM:SS from a Date object.

    JavaScript, Date · Oct 19, 2020

  • String is ISO formatted date

    Checks if the given string is valid in the simplified extended ISO format (ISO 8601).

    JavaScript, Date · Nov 29, 2020

  • Quarter of year

    Returns the quarter and year to which the supplied date belongs to.

    JavaScript, Date · Oct 22, 2020