This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Core Module
Overview
Core
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Console
  • DataView
  • Date
    • t
      t
    • t
      msSinceEpoch
    • t
      localeOptions
    • v
      make
    • v
      fromString
    • v
      fromTime
    • v
      makeWithYM
    • v
      makeWithYMD
    • v
      makeWithYMDH
    • v
      makeWithYMDHM
    • v
      makeWithYMDHMS
    • v
      makeWithYMDHMSM
    • v
      now
    • v
      equal
    • v
      compare
    • v
      getTime
    • v
      getTimezoneOffset
    • v
      getFullYear
    • v
      getMonth
    • v
      getDate
    • v
      getHours
    • v
      getMinutes
    • v
      getSeconds
    • v
      getMilliseconds
    • v
      getDay
    • v
      setFullYear
    • v
      setFullYearM
    • v
      setFullYearMD
    • v
      setMonth
    • v
      setDate
    • v
      setHours
    • v
      setHoursM
    • v
      setHoursMS
    • v
      setHoursMSMs
    • v
      setMinutes
    • v
      setMinutesS
    • v
      setMinutesSMs
    • v
      setSeconds
    • v
      setSecondsMs
    • v
      setMilliseconds
    • v
      getUTCFullYear
    • v
      getUTCMonth
    • v
      getUTCDate
    • v
      getUTCHours
    • v
      getUTCMinutes
    • v
      getUTCSeconds
    • v
      getUTCMilliseconds
    • v
      getUTCDay
    • v
      setUTCFullYear
    • v
      setUTCFullYearM
    • v
      setUTCFullYearMD
    • v
      setUTCMonth
    • v
      setUTCDate
    • v
      setUTCHours
    • v
      setUTCHoursM
    • v
      setUTCHoursMS
    • v
      setUTCHoursMSMs
    • v
      setUTCMinutes
    • v
      setUTCMinutesS
    • v
      setUTCMinutesSMs
    • v
      setUTCSeconds
    • v
      setUTCSecondsMs
    • v
      setUTCMilliseconds
    • v
      toDateString
    • v
      toString
    • v
      toTimeString
    • v
      toLocaleDateString
    • v
      toLocaleDateStringWithLocale
    • v
      toLocaleDateStringWithLocaleAndOptions
    • v
      toLocaleString
    • v
      toLocaleStringWithLocale
    • v
      toLocaleStringWithLocaleAndOptions
    • v
      toLocaleTimeString
    • v
      toLocaleTimeStringWithLocale
    • v
      toLocaleTimeStringWithLocaleAndOptions
    • v
      toISOString
    • v
      toUTCString
    • v
      toJSON
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • Internal
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
  • List
  • Map
  • MapperRt
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Promise
  • Re
    • Result
    RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • API / Core / Date

    Date

    Functions for interacting with JavaScript Dates.

    t

    RESCRIPT
    type t = Js.Date.t

    A type representing a JavaScript date.

    msSinceEpoch

    RESCRIPT
    type msSinceEpoch = float

    Time, in milliseconds, since / until the UNIX epoch (January 1, 1970 00:00:00 UTC). Positive numbers represent dates after, negative numbers dates before epoch.

    localeOptions

    RESCRIPT
    type localeOptions = { dateStyle?: [#full | #long | #medium | #short], timeStyle?: [#full | #long | #medium | #short], weekday?: [#long | #narrow | #short], era?: [#long | #narrow | #short], year?: [#"2-digit" | #numeric], month?: [ | #"2-digit" | #long | #narrow | #numeric | #short ], day?: [#"2-digit" | #numeric], hour?: [#"2-digit" | #numeric], minute?: [#"2-digit" | #numeric], second?: [#"2-digit" | #numeric], timeZoneName?: [#long | #short], }

    A type representing date time format options.

    Note: There are some properties missing:

    • fractionalSecondDigits

    • dayPeriod

    • calendar

    • numberingSystem

    • localeMatcher

    • timeZone

    • hour12

    • hourCycle

    • formatMatcher

    See full spec at https://tc39.es/ecma402/#datetimeformat-objects

    make

    RESCRIPT
    let make: unit => t

    make()

    Creates a date object with the current date time as value.

    Examples

    RESCRIPT
    Date.make()

    fromString

    RESCRIPT
    let fromString: string => t

    fromString(dateTimeString)

    Creates a date object from given date time string. The string has to be in the ISO 8601 format YYYY-MM-DDTHH:mm:ss.sssZ (https://tc39.es/ecma262/#sec-date-time-string-format).

    Invalid date time strings will create invalid dates. You can use the result like any valid date, but many functions like toString will return "Invalid Date" or functions like Date.getTime will return NaN.

    Examples

    RESCRIPT
    Date.fromString("2023") // 2023-01-01T00:00:00.000Z Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z Date.fromString("") // Invalid Date Date.fromString("")->Date.getTime // NaN

    fromTime

    RESCRIPT
    let fromTime: msSinceEpoch => t

    fromTime(msSinceEpoch)

    Creates a date object from the given time in milliseconds since / until UNIX epoch (January 1, 1970 00:00:00 UTC). Positive numbers create dates after epoch, negative numbers create dates before epoch.

    Examples

    RESCRIPT
    Date.fromTime(0.0) // 1970-01-01T00:00:00.000Z Date.fromTime(-86_400_000.0) // 1969-12-31T00:00:00.000Z Date.fromTime(86_400_000.0) // 1970-01-02T00:00:00.000Z

    makeWithYM

    RESCRIPT
    let makeWithYM: (~year: int, ~month: int) => t

    Creates a date object with the given year and month. Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example).

    Examples

    RESCRIPT
    Date.makeWithYM(~year=2023, ~month=0) // 2023-01-01T00:00:00.000Z Date.makeWithYM(~year=2023, ~month=11) // 2023-12-01T00:00:00.000Z Date.makeWithYM(~year=2023, ~month=12) // 2024-01-01T00:00:00.000Z Date.makeWithYM(~year=2023, ~month=-1) // 2022-12-01T00:00:00.000Z // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)

    makeWithYMD

    RESCRIPT
    let makeWithYMD: (~year: int, ~month: int, ~date: int) => t

    Creates a date object with the given year, month and date (day of month). Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example).

    Examples

    RESCRIPT
    Date.makeWithYMD(~year=2023, ~month=1, ~date=20) // 2023-02-20T00:00:00.000Z Date.makeWithYMD(~year=2023, ~month=1, ~date=-1) // 2022-11-29T00:00:00.000Z Date.makeWithYMD(~year=2023, ~month=1, ~date=29) // 2023-03-01T00:00:00.000Z

    makeWithYMDH

    RESCRIPT
    let makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => t

    Creates a date object with the given year, month, date (day of month) and hours. Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example).

    Examples

    RESCRIPT
    Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) // 2023-02-20T16:00:00.000Z Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) // 2023-02-21T00:00:00.000Z Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) // 2023-02-19T23:00:00.000Z // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)

    makeWithYMDHM

    RESCRIPT
    let makeWithYMDHM: ( ~year: int, ~month: int, ~date: int, ~hours: int, ~minutes: int, ) => t

    Creates a date object with the given year, month, date (day of month), hours and minutes. Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example).

    Examples

    RESCRIPT
    Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) // 2023-02-20T16:40:00.000Z Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) // 2023-02-20T17:00:00.000Z Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) // 2023-02-20T15:59:00.000Z // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)

    makeWithYMDHMS

    RESCRIPT
    let makeWithYMDHMS: ( ~year: int, ~month: int, ~date: int, ~hours: int, ~minutes: int, ~seconds: int, ) => t

    Creates a date object with the given year, month, date (day of month), hours, minutes and seconds. Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example).

    Examples

    RESCRIPT
    Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) // 2023-02-20T16:40:00.000Z Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) // 2023-02-20T16:41:00.000Z Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) // 2023-02-20T16:39:59.000Z // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)

    makeWithYMDHMSM

    RESCRIPT
    let makeWithYMDHMSM: ( ~year: int, ~month: int, ~date: int, ~hours: int, ~minutes: int, ~seconds: int, ~milliseconds: int, ) => t

    Creates a date object with the given year, month, date (day of month), hours, minutes, seconds and milliseconds. Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example).

    Examples

    RESCRIPT
    Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0) // 2023-02-20T16:40:00.000Z Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000) // 2023-02-20T16:40:01.000Z Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1) // 2023-02-20T16:39:59.999Z // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)

    now

    RESCRIPT
    let now: unit => msSinceEpoch

    now()

    Returns the time, in milliseconds, between UNIX epoch (January 1, 1970 00:00:00 UTC) and the current date time.

    equal

    RESCRIPT
    let equal: (t, t) => bool

    compare

    RESCRIPT
    let compare: (t, t) => Core__Ordering.t

    getTime

    RESCRIPT
    let getTime: t => msSinceEpoch

    getTime(date)

    Returns the time, in milliseconds, between UNIX epoch (January 1, 1970 00:00:00 UTC) and the current date time. Invalid dates will return NaN. Dates before epoch will return negative numbers.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20")->Date.getTime // 1676851200000

    getTimezoneOffset

    RESCRIPT
    let getTimezoneOffset: t => int

    getTimezoneOffset(date)

    Returns the time in minutes between the UTC time and the locale time. The timezone of the given date doesn't matter.

    Examples

    RESCRIPT
    Date.fromString("2023-01-01")->Date.getTimezoneOffset // -60 with local time zone = Europe/Berlin Date.fromString("2023-06-01")->Date.getTimezoneOffset // -120 with local time zone = Europe/Berlin

    getFullYear

    RESCRIPT
    let getFullYear: t => int

    getFullYear(date)

    Returns the year of a given date (according to local time).

    Examples

    RESCRIPT
    Date.fromString("2023-02-20")->Date.getFullYear // 2023

    getMonth

    RESCRIPT
    let getMonth: t => int

    getMonth(date)

    Returns the month (0-indexed) of a given date (according to local time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01")->Date.getMonth // 0

    getDate

    RESCRIPT
    let getDate: t => int

    getDate(date)

    Returns the date (day of month) of a given date (according to local time).

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.getDate // 20

    getHours

    RESCRIPT
    let getHours: t => int

    getHours(date)

    Returns the hours of a given date (according to local time).

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.getHours // 16

    getMinutes

    RESCRIPT
    let getMinutes: t => int

    getMinutes(date)

    Returns the minutes of a given date (according to local time).

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes // 40

    getSeconds

    RESCRIPT
    let getSeconds: t => int

    getSeconds(date)

    Returns the seconds of a given date (according to local time).

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds // 0

    getMilliseconds

    RESCRIPT
    let getMilliseconds: t => int

    getMilliseconds(date)

    Returns the milliseconds of a given date (according to local time).

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds // 0

    getDay

    RESCRIPT
    let getDay: t => int

    getDay(date)

    Returns the day of week of a given date (according to local time). 0 = Sunday, 1 = Monday, ... 6 = Saturday

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.getDay // 1

    setFullYear

    RESCRIPT
    let setFullYear: (t, int) => unit

    setFullYear(date, year)

    Sets the year of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024)

    setFullYearM

    RESCRIPT
    let setFullYearM: (t, ~year: int, ~month: int) => unit

    setFullYearM(date, ~year, ~month)

    Sets the year and month of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0)

    setFullYearMD

    RESCRIPT
    let setFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit

    setFullYearMD(date, ~year, ~month, ~date)

    Sets the year, month and date (day of month) of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1)

    setMonth

    RESCRIPT
    let setMonth: (t, int) => unit

    setMonth(date, month)

    Sets the month of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0)

    setDate

    RESCRIPT
    let setDate: (t, int) => unit

    setDate(date, day)

    Sets the date (day of month) of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1)

    setHours

    RESCRIPT
    let setHours: (t, int) => unit

    setHours(date, hours)

    Sets the hours of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0)

    setHoursM

    RESCRIPT
    let setHoursM: (t, ~hours: int, ~minutes: int) => unit

    setHoursM(date, ~hours, ~minutes)

    Sets the hours and minutes of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0)

    setHoursMS

    RESCRIPT
    let setHoursMS: (t, ~hours: int, ~minutes: int, ~seconds: int) => unit

    setHoursMS(date, ~hours, ~minutes, ~seconds)

    Sets the hours, minutes and seconds of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0)

    setHoursMSMs

    RESCRIPT
    let setHoursMSMs: ( t, ~hours: int, ~minutes: int, ~seconds: int, ~milliseconds: int, ) => unit

    setHoursMSMs(date, ~hours, ~minutes, ~seconds, ~milliseconds)

    Sets the hours, minutes, seconds and milliseconds of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs(~hours=0, ~minutes=0, ~seconds=0, ~milliseconds=0)

    setMinutes

    RESCRIPT
    let setMinutes: (t, int) => unit

    setMinutes(date, minutes)

    Sets the minutes of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0)

    setMinutesS

    RESCRIPT
    let setMinutesS: (t, ~minutes: int, ~seconds: int) => unit

    setMinutesS(date, ~minutes, ~seconds)

    Sets the minutes and seconds of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0)

    setMinutesSMs

    RESCRIPT
    let setMinutesSMs: ( t, ~minutes: int, ~seconds: int, ~milliseconds: int, ) => unit

    setMinutesSMs(date, ~minutes, ~seconds, ~milliseconds)

    Sets the minutes, seconds and milliseconds of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs(~minutes=0, ~seconds=0, ~milliseconds=0)

    setSeconds

    RESCRIPT
    let setSeconds: (t, int) => unit

    setSeconds(date, seconds)

    Sets the seconds of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0)

    setSecondsMs

    RESCRIPT
    let setSecondsMs: (t, ~seconds: int, ~milliseconds: int) => unit

    setSecondsMs(date, ~seconds, ~milliseconds)

    Sets the seconds and milliseconds of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0)

    setMilliseconds

    RESCRIPT
    let setMilliseconds: (t, int) => unit

    setMilliseconds(date, milliseconds)

    Sets the milliseconds of a date (according to local time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0)

    getUTCFullYear

    RESCRIPT
    let getUTCFullYear: t => int

    getUTCFullYear(date)

    Returns the year of a given date (according to UTC time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022

    getUTCMonth

    RESCRIPT
    let getUTCMonth: t => int

    getUTCMonth(date)

    Returns the month of a given date (according to UTC time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11

    getUTCDate

    RESCRIPT
    let getUTCDate: t => int

    getUTCDate(date)

    Returns the date (day of month) of a given date (according to UTC time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31

    getUTCHours

    RESCRIPT
    let getUTCHours: t => int

    getUTCHours(date)

    Returns the hours of a given date (according to UTC time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23

    getUTCMinutes

    RESCRIPT
    let getUTCMinutes: t => int

    getUTCMinutes(date)

    Returns the minutes of a given date (according to UTC time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0

    getUTCSeconds

    RESCRIPT
    let getUTCSeconds: t => int

    getUTCSeconds(date)

    Returns the seconds of a given date (according to UTC time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0

    getUTCMilliseconds

    RESCRIPT
    let getUTCMilliseconds: t => int

    getUTCMilliseconds(date)

    Returns the milliseconds of a given date (according to UTC time).

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0

    getUTCDay

    RESCRIPT
    let getUTCDay: t => int

    getUTCDay(date)

    Returns the day (day of week) of a given date (according to UTC time). 0 = Sunday, 1 = Monday, ... 6 = Saturday

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6

    setUTCFullYear

    RESCRIPT
    let setUTCFullYear: (t, int) => unit

    setUTCFullYear(date, year)

    Sets the year of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024)

    setUTCFullYearM

    RESCRIPT
    let setUTCFullYearM: (t, ~year: int, ~month: int) => unit

    setUTCFullYearM(date, ~year, ~month)

    Sets the year and month of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0)

    setUTCFullYearMD

    RESCRIPT
    let setUTCFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit

    setUTCFullYearMD(date, ~year, ~month, ~date)

    Sets the year, month and date (day of month) of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD(~year=2024, ~month=0, ~date=1)

    setUTCMonth

    RESCRIPT
    let setUTCMonth: (t, int) => unit

    setUTCMonth(date, month)

    Sets the month of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0)

    setUTCDate

    RESCRIPT
    let setUTCDate: (t, int) => unit

    setDate(date, day)

    Sets the date (day of month) of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1)

    setUTCHours

    RESCRIPT
    let setUTCHours: (t, int) => unit

    setUTCHours(date, hours)

    Sets the hours of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0)

    setUTCHoursM

    RESCRIPT
    let setUTCHoursM: (t, ~hours: int, ~minutes: int) => unit

    setHoursM(date, ~hours, ~minutes)

    Sets the hours and minutes of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0)

    setUTCHoursMS

    RESCRIPT
    let setUTCHoursMS: (t, ~hours: int, ~minutes: int, ~seconds: int) => unit

    setUTCHoursMS(date, ~hours, ~minutes, ~seconds)

    Sets the hours, minutes and seconds of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMS(~hours=0, ~minutes=0, ~seconds=0)

    setUTCHoursMSMs

    RESCRIPT
    let setUTCHoursMSMs: ( t, ~hours: int, ~minutes: int, ~seconds: int, ~milliseconds: int, ) => unit

    setUTCHoursMSMs(date, ~hours, ~minutes, ~seconds, ~milliseconds)

    Sets the hours, minutes, seconds and milliseconds of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs(~hours=0, ~minutes=0, ~seconds=0, ~milliseconds=0)

    setUTCMinutes

    RESCRIPT
    let setUTCMinutes: (t, int) => unit

    setUTCMinutes(date, minutes)

    Sets the minutes of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutes(0)

    setUTCMinutesS

    RESCRIPT
    let setUTCMinutesS: (t, ~minutes: int, ~seconds: int) => unit

    setUTCMinutesS(date, ~minutes, ~seconds)

    Sets the minutes and seconds of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesS(~minutes=0, ~seconds=0)

    setUTCMinutesSMs

    RESCRIPT
    let setUTCMinutesSMs: ( t, ~minutes: int, ~seconds: int, ~milliseconds: int, ) => unit

    setUTCMinutesSMs(date, ~minutes, ~seconds, ~milliseconds)

    Sets the minutes, seconds and milliseconds of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs(~minutes=0, ~seconds=0, ~milliseconds=0)

    setUTCSeconds

    RESCRIPT
    let setUTCSeconds: (t, int) => unit

    setUTCSeconds(date, seconds)

    Sets the seconds of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSeconds(0)

    setUTCSecondsMs

    RESCRIPT
    let setUTCSecondsMs: (t, ~seconds: int, ~milliseconds: int) => unit

    setUTCSecondsMs(date, ~seconds, ~milliseconds)

    Sets the seconds and milliseconds of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSecondsMs(~seconds=0, ~milliseconds=0)

    setUTCMilliseconds

    RESCRIPT
    let setUTCMilliseconds: (t, int) => unit

    setUTCMilliseconds(date, milliseconds)

    Sets the milliseconds of a date (according to UTC time). Beware this will mutate the date.

    Examples

    RESCRIPT
    Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMilliseconds(0)

    toDateString

    RESCRIPT
    let toDateString: t => string

    toDateString(date)

    Converts a JavaScript date to a standard date string. The date will be mapped to the current time zone. If you want to convert it to a localized string, use Date.toLocaleDateString instead.

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toDateString->Console.log // Sun Jan 01 2023 Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toDateString->Console.log // Sat Dec 31 2022

    toString

    RESCRIPT
    let toString: t => string

    toString(date)

    Converts a JavaScript date to a standard date time string. The date will be mapped to the current time zone. If you want to convert it to a localized string, use Date.toLocaleString instead.

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toString->Console.log // Sun Jan 01 2023 00:00:00 GMT+0100 (Central European Standard Time) Date.fromString("2023-06-01T00:00:00.00+01:00")->Date.toString->Console.log // Thu Jun 01 2023 01:00:00 GMT+0200 (Central European Summer Time)

    toTimeString

    RESCRIPT
    let toTimeString: t => string

    toTimeString(date)

    Converts a JavaScript date to a standard time string. The date will be mapped to the current time zone. If you want to convert it to a localized string, use Date.toLocaleStimeString instead.

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toTimeString->Console.log // 00:00:00 GMT+0100 (Central European Standard Time) Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toTimeString->Console.log // 17:00:00 GMT+0100 (Central European Standard Time)

    toLocaleDateString

    RESCRIPT
    let toLocaleDateString: t => string

    toLocaleDateString(date)

    Converts a JavaScript date to a localized date string. It will use the current locale.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleDateString->Console.log // 2/19/2023

    toLocaleDateStringWithLocale

    RESCRIPT
    let toLocaleDateStringWithLocale: (t, string) => string

    toLocaleDateStringWithLocale(date, locale)

    Converts a JavaScript date to a localized date string. It will use the specified locale.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log // 2/19/2023

    toLocaleDateStringWithLocaleAndOptions

    RESCRIPT
    let toLocaleDateStringWithLocaleAndOptions: (t, string, localeOptions) => string

    toLocaleDateStringWithLocaleAndOptions(date, locale, options)

    Converts a JavaScript date to a localized date string. It will use the specified locale and formatting options.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("en-US", { dateStyle: #long })->Console.log // February 19, 2023 Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log // 19.2.2023, 15:40 Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { year: #numeric })->Console.log // 2023

    toLocaleString

    RESCRIPT
    let toLocaleString: t => string

    toLocaleString(date)

    Converts a JavaScript date to a localized date-time string. It will use the current locale.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleString->Console.log // 2/19/2023, 3:40:00 PM

    toLocaleStringWithLocale

    RESCRIPT
    let toLocaleStringWithLocale: (t, string) => string

    toLocaleStringWithLocale(date, locale)

    Converts a JavaScript date to a localized date-time string. It will use the specified locale.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log // 2/19/2023, 3:40:00 PM

    toLocaleStringWithLocaleAndOptions

    RESCRIPT
    let toLocaleStringWithLocaleAndOptions: (t, string, localeOptions) => string

    toLocaleStringWithLocaleAndOptions(date, locale, options)

    Converts a JavaScript date to a localized date-time string. It will use the specified locale and formatting options.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { dateStyle: #short, timeStyle: #short })->Console.log // 2/19/23, 3:40 PM Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { era: #long, year: #numeric, month: #"2-digit", day: #"2-digit", hour: #numeric, timeZoneName: #short })->Console.log // 02/19/2023 Anno Domini, 3 PM GMT+1

    toLocaleTimeString

    RESCRIPT
    let toLocaleTimeString: t => string

    toLocaleTimeString(date)

    Converts a JavaScript date to a localized time string. It will use the current locale.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleTimeString->Console.log // 3:40:00 PM

    toLocaleTimeStringWithLocale

    RESCRIPT
    let toLocaleTimeStringWithLocale: (t, string) => string

    toLocaleTimeStringWithLocale(date, locale)

    Converts a JavaScript date to a localized time string. It will use the specified locale.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log // 3:40:00 PM

    toLocaleTimeStringWithLocaleAndOptions

    RESCRIPT
    let toLocaleTimeStringWithLocaleAndOptions: (t, string, localeOptions) => string

    toLocaleTimeStringWithLocaleAndOptions(date, locale, options)

    Converts a JavaScript date to a localized time string. It will use the specified locale and formatting options.

    Examples

    RESCRIPT
    Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", { timeStyle: #long })->Console.log // 3:40:00 PM GMT+1 Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log // 15:40

    toISOString

    RESCRIPT
    let toISOString: t => string

    toISOString(date)

    Converts a JavaScript date to a ISO 8601 string (YYYY-MM-DDTHH:mm:ss.sssZ). The date will be mapped to the UTC time.

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toISOString->Console.log // 2023-01-01T00:00:00.000Z Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toISOString->Console.log // 2022-12-31T16:00:00.000Z

    toUTCString

    RESCRIPT
    let toUTCString: t => string

    toUTCString(date)

    Converts a JavaScript date to date time string. The date will be mapped to the UTC time.

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toUTCString->Console.log // Sun, 01 Jan 2023 00:00:00 GMT Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toUTCString->Console.log // Sat, 31 Dec 2022 16:00:00 GMT

    toJSON

    RESCRIPT
    let toJSON: t => option<string>

    toJSON(date)

    Converts a JavaScript date to a string. If the date is valid, the function will return the same result as Date.toISOString. Invalid dates will return None.

    Examples

    RESCRIPT
    Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toJSON // Some("2023-01-01T00:00:00.000Z") Date.fromString("")->Date.toJSON // None
    Types and values
    • t
      t
    • t
      msSinceEpoch
    • t
      localeOptions
    • v
      make
    • v
      fromString
    • v
      fromTime
    • v
      makeWithYM
    • v
      makeWithYMD
    • v
      makeWithYMDH
    • v
      makeWithYMDHM
    • v
      makeWithYMDHMS
    • v
      makeWithYMDHMSM
    • v
      now
    • v
      equal
    • v
      compare
    • v
      getTime
    • v
      getTimezoneOffset
    • v
      getFullYear
    • v
      getMonth
    • v
      getDate
    • v
      getHours
    • v
      getMinutes
    • v
      getSeconds
    • v
      getMilliseconds
    • v
      getDay
    • v
      setFullYear
    • v
      setFullYearM
    • v
      setFullYearMD
    • v
      setMonth
    • v
      setDate
    • v
      setHours
    • v
      setHoursM
    • v
      setHoursMS
    • v
      setHoursMSMs
    • v
      setMinutes
    • v
      setMinutesS
    • v
      setMinutesSMs
    • v
      setSeconds
    • v
      setSecondsMs
    • v
      setMilliseconds
    • v
      getUTCFullYear
    • v
      getUTCMonth
    • v
      getUTCDate
    • v
      getUTCHours
    • v
      getUTCMinutes
    • v
      getUTCSeconds
    • v
      getUTCMilliseconds
    • v
      getUTCDay
    • v
      setUTCFullYear
    • v
      setUTCFullYearM
    • v
      setUTCFullYearMD
    • v
      setUTCMonth
    • v
      setUTCDate
    • v
      setUTCHours
    • v
      setUTCHoursM
    • v
      setUTCHoursMS
    • v
      setUTCHoursMSMs
    • v
      setUTCMinutes
    • v
      setUTCMinutesS
    • v
      setUTCMinutesSMs
    • v
      setUTCSeconds
    • v
      setUTCSecondsMs
    • v
      setUTCMilliseconds
    • v
      toDateString
    • v
      toString
    • v
      toTimeString
    • v
      toLocaleDateString
    • v
      toLocaleDateStringWithLocale
    • v
      toLocaleDateStringWithLocaleAndOptions
    • v
      toLocaleString
    • v
      toLocaleStringWithLocale
    • v
      toLocaleStringWithLocaleAndOptions
    • v
      toLocaleTimeString
    • v
      toLocaleTimeStringWithLocale
    • v
      toLocaleTimeStringWithLocaleAndOptions
    • v
      toISOString
    • v
      toUTCString
    • v
      toJSON

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on