#mizchi/js_builtin/date

    Date and time manipulation with JavaScript's Date API.

    #Installation

    Add to your moon.pkg.json:

    { "import": [ "mizchi/js", "mizchi/js_builtin/date" ] }

    #Overview

    Provides bindings for JavaScript's Date object for working with dates and times.

    #Usage Example

    fn main {
    // Create a new Date
    let now = @date.Date::new()

    // Get timestamp
    let timestamp = @date.Date::now()

    // Create from timestamp
    let date = @date.Date::from_time(1234567890000.0)

    // Get components
    let year = date.getFullYear()
    let month = date.getMonth()
    let day = date.getDate()

    // Convert to string
    let str = date.toISOString()
    }

    #Reference

    Date

    #external
    pub type Date

    JavaScript Date object wrapper.

    Represents a single moment in time in a platform-independent format. Corresponds to JavaScript's Date constructor and object. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

    Date::as_any

    fn Date::as_any(self : Date) ->
    Any

    Convert Date to Any for JS interop

    Date::from_full

    fn Date::from_full(year : Int, month : Int, day : Int, hours : Int, minutes : Int, seconds : Int, milliseconds : Int) -> Date

    Create a new Date object from full date and time components including milliseconds.

    JavaScript API: new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

    Date::from_millis

    fn Date::from_millis(value : Int) -> Date

    Create a new Date object from milliseconds since Unix epoch.

    JavaScript API: new Date(value) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

    Date::from_string

    fn Date::from_string(date_string : String) -> Date

    Create a new Date object from a date string.

    JavaScript API: new Date(dateString) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

    Date::from_ymd

    fn Date::from_ymd(year : Int, month : Int, day : Int) -> Date

    Create a new Date object from individual date components (year, month, day).

    JavaScript API: new Date(year, monthIndex, day) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

    Date::from_ymdhms

    fn Date::from_ymdhms(year : Int, month : Int, day : Int, hours : Int, minutes : Int, seconds : Int) -> Date

    Create a new Date object from individual date and time components.

    JavaScript API: new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

    Date::get_date

    fn Date::get_date(self : Date) -> Int

    Get the day of the month (1-31) for the specified date according to local time.

    JavaScript API: Date.prototype.getDate() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate

    Date::get_day

    fn Date::get_day(self : Date) -> Int

    Get the day of the week (0-6) for the specified date according to local time.

    JavaScript API: Date.prototype.getDay() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay

    Date::get_full_year

    fn Date::get_full_year(self : Date) -> Int

    Get the year (4 digits) of the specified date according to local time.

    JavaScript API: Date.prototype.getFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear

    Date::get_hours

    fn Date::get_hours(self : Date) -> Int

    Get the hours (0-23) for the specified date according to local time.

    JavaScript API: Date.prototype.getHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours

    Date::get_milliseconds

    fn Date::get_milliseconds(self : Date) -> Int

    Get the milliseconds (0-999) for the specified date according to local time.

    JavaScript API: Date.prototype.getMilliseconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds

    Date::get_minutes

    fn Date::get_minutes(self : Date) -> Int

    Get the minutes (0-59) for the specified date according to local time.

    JavaScript API: Date.prototype.getMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes

    Date::get_month

    fn Date::get_month(self : Date) -> Int

    Get the month (0-11) for the specified date according to local time.

    JavaScript API: Date.prototype.getMonth() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth

    Date::get_seconds

    fn Date::get_seconds(self : Date) -> Int

    Get the seconds (0-59) for the specified date according to local time.

    JavaScript API: Date.prototype.getSeconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds

    Date::get_time

    fn Date::get_time(self : Date) -> Int

    Get the time value in milliseconds since Unix epoch.

    JavaScript API: Date.prototype.getTime() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime

    Date::get_timezone_offset

    fn Date::get_timezone_offset(self : Date) -> Int

    Get the timezone offset in minutes from UTC.

    JavaScript API: Date.prototype.getTimezoneOffset() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

    Date::get_utc_date

    fn Date::get_utc_date(self : Date) -> Int

    Get the day of the month (1-31) for the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCDate() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate

    Date::get_utc_day

    fn Date::get_utc_day(self : Date) -> Int

    Get the day of the week (0-6) for the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCDay() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay

    Date::get_utc_full_year

    fn Date::get_utc_full_year(self : Date) -> Int

    Get the year (4 digits) of the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear

    Date::get_utc_hours

    fn Date::get_utc_hours(self : Date) -> Int

    Get the hours (0-23) for the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours

    Date::get_utc_milliseconds

    fn Date::get_utc_milliseconds(self : Date) -> Int

    Get the milliseconds (0-999) for the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCMilliseconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds

    Date::get_utc_minutes

    fn Date::get_utc_minutes(self : Date) -> Int

    Get the minutes (0-59) for the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes

    Date::get_utc_month

    fn Date::get_utc_month(self : Date) -> Int

    Get the month (0-11) for the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCMonth() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth

    Date::get_utc_seconds

    fn Date::get_utc_seconds(self : Date) -> Int

    Get the seconds (0-59) for the specified date according to UTC.

    JavaScript API: Date.prototype.getUTCSeconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds

    Date::new

    fn Date::new() -> Date

    Create a new Date object with the current date and time.

    JavaScript API: new Date() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

    Date::now

    fn Date::now() -> Int

    Get the current time in milliseconds since Unix epoch (January 1, 1970, 00:00:00 UTC).

    JavaScript API: Date.now() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now

    Date::parse

    fn Date::parse(date_string : String) -> Int

    Parse a date string and return milliseconds since Unix epoch.

    JavaScript API: Date.parse() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

    Date::set_date

    fn Date::set_date(self : Date, day : Int) -> Int

    Set the day of the month for the specified date according to local time.

    JavaScript API: Date.prototype.setDate() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate

    Date::set_full_year

    fn Date::set_full_year(self : Date, year : Int, month : Int, day : Int) -> Int

    Set the full year for the specified date according to local time.

    JavaScript API: Date.prototype.setFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear

    Date::set_full_year_y

    fn Date::set_full_year_y(self : Date, year : Int) -> Int

    Set the full year for the specified date according to local time (year only).

    JavaScript API: Date.prototype.setFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear

    Date::set_full_year_ym

    fn Date::set_full_year_ym(self : Date, year : Int, month : Int) -> Int

    Set the full year for the specified date according to local time (with optional month).

    JavaScript API: Date.prototype.setFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear

    Date::set_hours

    fn Date::set_hours(self : Date, hours : Int, minutes : Int, seconds : Int, milliseconds : Int) -> Int

    Set the hours for the specified date according to local time.

    JavaScript API: Date.prototype.setHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours

    Date::set_hours_h

    fn Date::set_hours_h(self : Date, hours : Int) -> Int

    Set the hours for the specified date according to local time (hours only).

    JavaScript API: Date.prototype.setHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours

    Date::set_hours_hm

    fn Date::set_hours_hm(self : Date, hours : Int, minutes : Int) -> Int

    Set the hours for the specified date according to local time (with minutes).

    JavaScript API: Date.prototype.setHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours

    Date::set_hours_hms

    fn Date::set_hours_hms(self : Date, hours : Int, minutes : Int, seconds : Int) -> Int

    Set the hours for the specified date according to local time (with minutes, seconds).

    JavaScript API: Date.prototype.setHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours

    Date::set_milliseconds

    fn Date::set_milliseconds(self : Date, milliseconds : Int) -> Int

    Set the milliseconds for the specified date according to local time.

    JavaScript API: Date.prototype.setMilliseconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds

    Date::set_minutes

    fn Date::set_minutes(self : Date, minutes : Int, seconds : Int, milliseconds : Int) -> Int

    Set the minutes for the specified date according to local time.

    JavaScript API: Date.prototype.setMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes

    Date::set_minutes_m

    fn Date::set_minutes_m(self : Date, minutes : Int) -> Int

    Set the minutes for the specified date according to local time (minutes only).

    JavaScript API: Date.prototype.setMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes

    Date::set_minutes_ms

    fn Date::set_minutes_ms(self : Date, minutes : Int, seconds : Int) -> Int

    Set the minutes for the specified date according to local time (with seconds).

    JavaScript API: Date.prototype.setMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes

    Date::set_month

    fn Date::set_month(self : Date, month : Int, day : Int) -> Int

    Set the month for the specified date according to local time.

    JavaScript API: Date.prototype.setMonth() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth

    Date::set_month_m

    fn Date::set_month_m(self : Date, month : Int) -> Int

    Set the month for the specified date according to local time (month only).

    JavaScript API: Date.prototype.setMonth() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth

    Date::set_seconds

    fn Date::set_seconds(self : Date, seconds : Int, milliseconds : Int) -> Int

    Set the seconds for the specified date according to local time.

    JavaScript API: Date.prototype.setSeconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds

    Date::set_seconds_s

    fn Date::set_seconds_s(self : Date, seconds : Int) -> Int

    Set the seconds for the specified date according to local time (seconds only).

    JavaScript API: Date.prototype.setSeconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds

    Date::set_time

    fn Date::set_time(self : Date, time : Int) -> Int

    Set the time value in milliseconds since Unix epoch.

    JavaScript API: Date.prototype.setTime() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime

    Date::set_utc_date

    fn Date::set_utc_date(self : Date, day : Int) -> Int

    Set the day of the month for the specified date according to UTC.

    JavaScript API: Date.prototype.setUTCDate() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate

    Date::set_utc_full_year

    fn Date::set_utc_full_year(self : Date, year : Int, month : Int, day : Int) -> Int

    Set the full year for the specified date according to UTC.

    JavaScript API: Date.prototype.setUTCFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear

    Date::set_utc_full_year_y

    fn Date::set_utc_full_year_y(self : Date, year : Int) -> Int

    Set the full year for the specified date according to UTC (year only).

    JavaScript API: Date.prototype.setUTCFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear

    Date::set_utc_full_year_ym

    fn Date::set_utc_full_year_ym(self : Date, year : Int, month : Int) -> Int

    Set the full year for the specified date according to UTC (with optional month).

    JavaScript API: Date.prototype.setUTCFullYear() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear

    Date::set_utc_hours

    fn Date::set_utc_hours(self : Date, hours : Int, minutes : Int, seconds : Int, milliseconds : Int) -> Int

    Set the hours for the specified date according to UTC.

    JavaScript API: Date.prototype.setUTCHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours

    Date::set_utc_hours_h

    fn Date::set_utc_hours_h(self : Date, hours : Int) -> Int

    Set the hours for the specified date according to UTC (hours only).

    JavaScript API: Date.prototype.setUTCHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours

    Date::set_utc_hours_hm

    fn Date::set_utc_hours_hm(self : Date, hours : Int, minutes : Int) -> Int

    Set the hours for the specified date according to UTC (with minutes).

    JavaScript API: Date.prototype.setUTCHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours

    Date::set_utc_hours_hms

    fn Date::set_utc_hours_hms(self : Date, hours : Int, minutes : Int, seconds : Int) -> Int

    Set the hours for the specified date according to UTC (with minutes, seconds).

    JavaScript API: Date.prototype.setUTCHours() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours

    Date::set_utc_milliseconds

    fn Date::set_utc_milliseconds(self : Date, milliseconds : Int) -> Int

    Set the milliseconds for the specified date according to UTC.

    JavaScript API: Date.prototype.setUTCMilliseconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds

    Date::set_utc_minutes

    fn Date::set_utc_minutes(self : Date, minutes : Int, seconds : Int, milliseconds : Int) -> Int

    Set the minutes for the specified date according to UTC.

    JavaScript API: Date.prototype.setUTCMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes

    Date::set_utc_minutes_m

    fn Date::set_utc_minutes_m(self : Date, minutes : Int) -> Int

    Set the minutes for the specified date according to UTC (minutes only).

    JavaScript API: Date.prototype.setUTCMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes

    Date::set_utc_minutes_ms

    fn Date::set_utc_minutes_ms(self : Date, minutes : Int, seconds : Int) -> Int

    Set the minutes for the specified date according to UTC (with seconds).

    JavaScript API: Date.prototype.setUTCMinutes() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes

    Date::set_utc_month

    fn Date::set_utc_month(self : Date, month : Int, day : Int) -> Int

    Set the month for the specified date according to UTC.

    JavaScript API: Date.prototype.setUTCMonth() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth

    Date::set_utc_month_m

    fn Date::set_utc_month_m(self : Date, month : Int) -> Int

    Set the month for the specified date according to UTC (month only).

    JavaScript API: Date.prototype.setUTCMonth() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth

    Date::set_utc_seconds

    fn Date::set_utc_seconds(self : Date, seconds : Int, milliseconds : Int) -> Int

    Set the seconds for the specified date according to UTC.

    JavaScript API: Date.prototype.setUTCSeconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds

    Date::set_utc_seconds_s

    fn Date::set_utc_seconds_s(self : Date, seconds : Int) -> Int

    Set the seconds for the specified date according to UTC (seconds only).

    JavaScript API: Date.prototype.setUTCSeconds() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds

    Date::to_date_string

    fn Date::to_date_string(self : Date) -> String

    Convert the date to a string representing the date portion.

    JavaScript API: Date.prototype.toDateString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString

    Date::to_iso_string

    fn Date::to_iso_string(self : Date) -> String

    Convert the date to a string in ISO 8601 format.

    JavaScript API: Date.prototype.toISOString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

    Date::to_json

    fn Date::to_json(self : Date) -> String

    Convert the date to a JSON string representation.

    JavaScript API: Date.prototype.toJSON() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON

    Date::to_locale_date_string

    fn Date::to_locale_date_string(self : Date) -> String

    Convert the date to a string representing the date portion in the current locale.

    JavaScript API: Date.prototype.toLocaleDateString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

    Date::to_locale_string

    fn Date::to_locale_string(self : Date) -> String

    Convert the date to a string in the current locale.

    JavaScript API: Date.prototype.toLocaleString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

    Date::to_locale_time_string

    fn Date::to_locale_time_string(self : Date) -> String

    Convert the date to a string representing the time portion in the current locale.

    JavaScript API: Date.prototype.toLocaleTimeString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString

    Date::to_string

    fn Date::to_string(self : Date) -> String

    Convert the date to a human-readable string.

    JavaScript API: Date.prototype.toString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString

    Date::to_time_string

    fn Date::to_time_string(self : Date) -> String

    Convert the date to a string representing the time portion.

    JavaScript API: Date.prototype.toTimeString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString

    Date::to_utc_string

    fn Date::to_utc_string(self : Date) -> String

    Convert the date to a string in UTC format.

    JavaScript API: Date.prototype.toUTCString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString

    Date::utc

    fn Date::utc(year : Int, month : Int, day : Int, hours : Int, minutes : Int, seconds : Int, milliseconds : Int) -> Int

    Create a Date from UTC time components.

    JavaScript API: Date.UTC() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC

    Date::value_of

    fn Date::value_of(self : Date) -> Int

    Get the primitive value of the Date object (milliseconds since Unix epoch).

    JavaScript API: Date.prototype.valueOf() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io