Bitbybit Docs
    Preparing search index...

    Class Dates

    Dates and times as JavaScript Date values: creating them, reading and setting their parts, and formatting them as text. Months count from 0 (January is 0, December 11) and weekdays from 0 (Sunday); days of the month count from 1. Every setter returns a new date and leaves the given one unchanged. Local-time and UTC variants exist for most operations.

    Index

    Constructors

    convert

    • Formats the date part as text, without the time, in the local time zone.

      Example: 15 January 2024 at 14:30 -> 'Mon Jan 15 2024'

      Parameters

      Returns string

      The date as text such as 'Mon Jan 15 2024'

    • Formats the date and time in the ISO 8601 form used for data exchange, always in UTC.

      Example: 15 January 2024 at 14:30 -> '2024-01-15T14:30:45.000Z'

      Parameters

      Returns string

      The date as text such as '2024-01-15T14:30:45.000Z'

    • Formats the date the way it appears inside JSON, which is the ISO 8601 form in UTC.

      Example: 15 January 2024 at 14:30 -> '2024-01-15T14:30:00.000Z'

      Parameters

      Returns string

      The date as text such as '2024-01-15T14:30:00.000Z'

    • Formats the full date and time as text in the local time zone, with the zone offset.

      Example: 15 January 2024 at 14:30 -> 'Mon Jan 15 2024 14:30:00 GMT+0000'

      Parameters

      Returns string

      The date and time as text

    • Formats the time part as text, without the date, in the local time zone with the zone offset.

      Example: 15 January 2024 at 14:30 -> '14:30:45 GMT+0000'

      Parameters

      Returns string

      The time as text such as '14:30:45 GMT+0000'

    • Formats the date and time as text in UTC.

      Example: 15 January 2024 at 14:30 -> 'Mon, 15 Jan 2024 14:30:00 GMT'

      Parameters

      Returns string

      The date and time as UTC text

    create

    • Gives the current date and time at the moment of the call.

      Returns Date

      The current date and time

    • Builds a date from its parts, read in the local time zone.

      The month counts from 0: 0 is January, 11 December. A part outside its range rolls over, so day 32 of January becomes the first of February. Example: year 2024, month 0, day 15, hours 14, minutes 30 -> 15 January 2024 at 14:30 local time

      Parameters

      • inputs: CreateDateDto

        The year, month, day, hours, minutes, seconds and milliseconds

      Returns Date

      The date

      const date = bitbybit.dates.createDate({ year: 2024, month: 0, day: 15, hours: 14, minutes: 30, seconds: 0, milliseconds: 0 });
      
    • Builds a date from its parts, read as UTC so the local time zone plays no part.

      The month counts from 0: 0 is January, 11 December. A part outside its range rolls over. Example: year 2024, month 0, day 15 -> 15 January 2024 at 00:00 UTC

      Parameters

      • inputs: CreateDateDto

        The year, month, day, hours, minutes, seconds and milliseconds

      Returns Date

      The date

      const date = bitbybit.dates.createDateUTC({ year: 2024, month: 0, day: 15, hours: 0, minutes: 0, seconds: 0, milliseconds: 0 });
      
    • Builds a date from a Unix timestamp: the number of milliseconds since 1 January 1970 at 00:00 UTC.

      Example: 1705329000000 -> 15 January 2024 at 14:30 UTC

      Parameters

      Returns Date

      The date

      const date = bitbybit.dates.createFromUnixTimeStamp({ unixTimeStamp: 1705329000000 });
      

    get

    • Reads the day of the month, from 1 to 31, in the local time zone.

      Example: 15 January 2024 -> 15

      Parameters

      Returns number

      The day of the month

    • Reads the day of the week in the local time zone: 0 is Sunday, 6 Saturday.

      Example: 15 January 2024 -> 1, a Monday

      Parameters

      Returns number

      The weekday from 0 to 6

    • Reads the full year in the local time zone.

      Example: 15 January 2024 -> 2024

      Parameters

      Returns number

      The year

    • Reads the month in the local time zone, counting from 0: 0 is January, 11 December.

      Example: 15 January 2024 -> 0

      Parameters

      Returns number

      The month from 0 to 11

    • Reads the hour, from 0 to 23, in the local time zone.

      Example: 14:30 -> 14

      Parameters

      Returns number

      The hour

    • Reads the minutes, from 0 to 59, in the local time zone.

      Example: 14:30 -> 30

      Parameters

      Returns number

      The minutes

    • Reads the seconds, from 0 to 59, in the local time zone.

      Example: 14:30:45 -> 45

      Parameters

      Returns number

      The seconds

    • Reads the milliseconds, from 0 to 999, in the local time zone.

      Example: 14:30:45.123 -> 123

      Parameters

      Returns number

      The milliseconds

    • Gives the date as a Unix timestamp: the milliseconds since 1 January 1970 at 00:00 UTC.

      Example: 15 January 2024 at 14:30 UTC -> 1705329000000

      Parameters

      Returns number

      The timestamp in milliseconds

    • Reads the full year in UTC.

      Example: 15 January 2024 -> 2024

      Parameters

      Returns number

      The year

    • Reads the month in UTC, counting from 0: 0 is January, 11 December.

      Example: 15 January 2024 -> 0

      Parameters

      Returns number

      The month from 0 to 11

    • Reads the day of the month, from 1 to 31, in UTC.

      Example: 15 January 2024 -> 15

      Parameters

      Returns number

      The day of the month

    • Reads the hour, from 0 to 23, in UTC.

      Example: 14:00 UTC -> 14

      Parameters

      Returns number

      The hour

    • Reads the minutes, from 0 to 59, in UTC.

      Example: 14:30 UTC -> 30

      Parameters

      Returns number

      The minutes

    • Reads the seconds, from 0 to 59, in UTC.

      Example: 14:30:45 UTC -> 45

      Parameters

      Returns number

      The seconds

    • Reads the milliseconds, from 0 to 999, in UTC.

      Example: 14:30:45.123 UTC -> 123

      Parameters

      Returns number

      The milliseconds

    parse

    • Reads a date written as text and gives its Unix timestamp, the milliseconds since 1 January 1970 at 00:00 UTC.

      ISO 8601 text such as '2024-01-15' or '2024-01-15T14:30:00Z' is read reliably; text that cannot be read gives NaN. Example: '2024-01-15' -> 1705276800000

      Parameters

      Returns number

      The timestamp in milliseconds, or NaN when the text is not a date

      const stamp = bitbybit.dates.parseDate({ dateString: "2024-01-15T14:30:00Z" });
      

    set

    • Makes a copy of the date with another year, in the local time zone. The given date is not changed.

      Example: 15 January 2024 with year 2025 -> 15 January 2025

      Parameters

      Returns Date

      A new date with the year changed

      const changed = bitbybit.dates.setYear({ date: bitbybit.dates.now(), year: 2025 });
      
    • Makes a copy of the date with another month, in the local time zone; months count from 0. The given date is not changed.

      Example: 15 January 2024 with month 5 -> 15 June 2024

      Parameters

      Returns Date

      A new date with the month changed

      const changed = bitbybit.dates.setMonth({ date: bitbybit.dates.now(), month: 5 });
      
    • Makes a copy of the date with another day of the month, in the local time zone. The given date is not changed.

      Example: 15 January 2024 with day 20 -> 20 January 2024

      Parameters

      • inputs: DateDayDto

        The date and the day from 1 to 31

      Returns Date

      A new date with the day changed

      const changed = bitbybit.dates.setDayOfMonth({ date: bitbybit.dates.now(), day: 20 });
      
    • Makes a copy of the date with another hour, in the local time zone. The given date is not changed.

      Example: 14:30 with hours 9 -> 09:30

      Parameters

      Returns Date

      A new date with the hour changed

      const changed = bitbybit.dates.setHours({ date: bitbybit.dates.now(), hours: 9 });
      
    • Makes a copy of the date with other minutes, in the local time zone. The given date is not changed.

      Example: 14:30 with minutes 45 -> 14:45

      Parameters

      Returns Date

      A new date with the minutes changed

      const changed = bitbybit.dates.setMinutes({ date: bitbybit.dates.now(), minutes: 45 });
      
    • Makes a copy of the date with other seconds, in the local time zone. The given date is not changed.

      Example: 14:30:00 with seconds 30 -> 14:30:30

      Parameters

      Returns Date

      A new date with the seconds changed

      const changed = bitbybit.dates.setSeconds({ date: bitbybit.dates.now(), seconds: 30 });
      
    • Makes a copy of the date with other milliseconds, in the local time zone. The given date is not changed.

      Example: 14:30:00.000 with milliseconds 500 -> 14:30:00.500

      Parameters

      Returns Date

      A new date with the milliseconds changed

      const changed = bitbybit.dates.setMilliseconds({ date: bitbybit.dates.now(), milliseconds: 500 });
      
    • Makes a copy of the date moved to a Unix timestamp, the milliseconds since 1 January 1970 at 00:00 UTC. The given date is not changed.

      Example: any date with time 0 -> 1 January 1970 at 00:00 UTC

      Parameters

      • inputs: DateTimeDto

        The date and the timestamp in milliseconds

      Returns Date

      A new date with the timestamp changed

      const changed = bitbybit.dates.setTime({ date: bitbybit.dates.now(), time: 1705329000000 });
      
    • Makes a copy of the date with another year, in UTC. The given date is not changed.

      Example: 15 January 2024 with year 2025 -> 15 January 2025

      Parameters

      Returns Date

      A new date with the year changed

      const changed = bitbybit.dates.setUTCYear({ date: bitbybit.dates.now(), year: 2025 });
      
    • Makes a copy of the date with another month, in UTC; months count from 0. The given date is not changed.

      Example: 15 January 2024 with month 5 -> 15 June 2024

      Parameters

      Returns Date

      A new date with the month changed

      const changed = bitbybit.dates.setUTCMonth({ date: bitbybit.dates.now(), month: 5 });
      
    • Makes a copy of the date with another day of the month, in UTC. The given date is not changed.

      Example: 15 January 2024 with day 20 -> 20 January 2024

      Parameters

      • inputs: DateDayDto

        The date and the day from 1 to 31

      Returns Date

      A new date with the day changed

      const changed = bitbybit.dates.setUTCDay({ date: bitbybit.dates.now(), day: 20 });
      
    • Makes a copy of the date with another hour, in UTC. The given date is not changed.

      Example: 14:30 UTC with hours 9 -> 09:30 UTC

      Parameters

      Returns Date

      A new date with the hour changed

      const changed = bitbybit.dates.setUTCHours({ date: bitbybit.dates.now(), hours: 9 });
      
    • Makes a copy of the date with other minutes, in UTC. The given date is not changed.

      Example: 14:30 UTC with minutes 45 -> 14:45 UTC

      Parameters

      Returns Date

      A new date with the minutes changed

      const changed = bitbybit.dates.setUTCMinutes({ date: bitbybit.dates.now(), minutes: 45 });
      
    • Makes a copy of the date with other seconds, in UTC. The given date is not changed.

      Example: 14:30:00 UTC with seconds 30 -> 14:30:30 UTC

      Parameters

      Returns Date

      A new date with the seconds changed

      const changed = bitbybit.dates.setUTCSeconds({ date: bitbybit.dates.now(), seconds: 30 });
      
    • Makes a copy of the date with other milliseconds, in UTC. The given date is not changed.

      Example: 14:30:00.000 UTC with milliseconds 500 -> 14:30:00.500 UTC

      Parameters

      Returns Date

      A new date with the milliseconds changed

      const changed = bitbybit.dates.setUTCMilliseconds({ date: bitbybit.dates.now(), milliseconds: 500 });