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.

  • formatDuration

    JavaScript, Date

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

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

  • addMinutesToDate

    JavaScript, Date

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

  • countWeekDaysBetween

    JavaScript, Date

    Counts the weekdays between two dates.

  • toISOStringWithTimezone

    JavaScript, Date

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

  • isDateValid

    JavaScript, Date

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

  • addWeekDays

    JavaScript, Date

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

  • addDaysToDate

    JavaScript, Date

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

  • isISOString

    JavaScript, Date

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

  • getColonTimeFromDate

    JavaScript, Date

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

  • quarterOfYear

    JavaScript, Date

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

  • dayOfYear

    JavaScript, Date

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

  • maxDate

    JavaScript, Date

    Returns the maximum of the given dates.

  • minDate

    JavaScript, Date

    Returns the minimum of the given dates.

  • dayName

    JavaScript, Date

    Gets the name of the weekday from a Date object.