JavaScriptKit Documentation

Class JSDate

public final class JSDate: JSBridgedClass  

A wrapper around the JavaScript Date class that exposes its properties in a type-safe way. This doesn't 100% match the JS API, for example getMonth/setMonth etc accessor methods are converted to properties, but the rest of it matches in the naming. Parts of the JavaScript Date API that are not consistent across browsers and JS implementations are not exposed in a type-safe manner, you should access the underlying jsObject property if you need those.

%151 JSDate JSDate JSBridgedClass JSBridgedClass JSDate->JSBridgedClass Comparable Comparable JSDate->Comparable

Conforms To

JSBridgedClass

Conform to this protocol when your Swift class wraps a JavaScript class.

Comparable

Initializers

init(milliseconds​Since​Epoch:​)

public init(millisecondsSinceEpoch: Double? = nil)  

Creates a new instance of the JavaScript Date class with a given amount of milliseconds that passed since midnight 01 January 1970 UTC.

init(year:​month​Index:​day:​hours:​minutes:​seconds:​milliseconds:​)

public init(
        year: Int,
        monthIndex: Int,
        day: Int = 1,
        hours: Int = 0,
        minutes: Int = 0,
        seconds: Int = 0,
        milliseconds: Int = 0
    )  

According to the standard, monthIndex is zero-indexed, where 11 is December. day represents a day of the month starting at 1.

init(unsafely​Wrapping:​)

public init(unsafelyWrapping jsObject: JSObject)  

Properties

constructor

public static let constructor = JSObject.global.Date.function

The constructor function used to create new Date objects.

js​Object

public let jsObject: JSObject

The underlying JavaScript Date object.

full​Year

public var fullYear: Int  

Year of this date in local time zone.

month

public var month: Int  

Month of this date in 0–11 range in local time zone.

date

public var date: Int  

The day of the month in 1..31 range in local time zone.

day

public var day: Int  

The day of the week in 0..6 range in local time zone.

hours

public var hours: Int  

The amount of hours in this day from 0..23 range in local time zone.

minutes

public var minutes: Int  

The amount of minutes in this hours from 0..59 range in local time zone.

seconds

public var seconds: Int  

The amount of seconds in this minute from 0..59 range in local time zone.

milliseconds

public var milliseconds: Int  

The amount of milliseconds in this second 0..999 range in local time zone.

utc​Full​Year

public var utcFullYear: Int  

Year of this date in the UTC time zone.

utc​Month

public var utcMonth: Int  

Month of this date in 0–11 range in the UTC time zone.

utc​Date

public var utcDate: Int  

The day of the month in 1..31 range in the UTC time zone.

utc​Day

public var utcDay: Int  

The day of the week in 0..6 range in the UTC time zone.

utc​Hours

public var utcHours: Int  

The amount of hours in this day from 0..23 range in the UTC time zone.

utc​Minutes

public var utcMinutes: Int  

The amount of minutes in this hours from 0..59 range in the UTC time zone.

utc​Seconds

public var utcSeconds: Int  

The amount of seconds in this minute from 0..59 range in the UTC time zone.

utc​Milliseconds

public var utcMilliseconds: Int  

The amount of milliseconds in this second 0..999 range in the UTC time zone.

timezone​Offset

public var timezoneOffset: Int  

Offset in minutes between the local time zone and UTC.

Methods

to​ISOString()

public func toISOString() -> String  

Returns a string conforming to ISO 8601 that contains date and time, e.g. "2020-09-15T08:56:54.811Z".

to​Locale​Date​String()

public func toLocaleDateString() -> String  

Returns a string with date parts in a format defined by user's locale, e.g. "9/15/2020".

to​Locale​Time​String()

public func toLocaleTimeString() -> String  

Returns a string with time parts in a format defined by user's locale, e.g. "10:04:14".

to​UTCString()

public func toUTCString() -> String  

Returns a string formatted according to rfc7231 and modified according to ecma-262, e.g. Tue, 15 Sep 2020 09:04:40 GMT.

now()

public static func now() -> Double  

Number of milliseconds since midnight 01 January 1970 UTC to the present moment ignoring leap seconds.

value​Of()

public func valueOf() -> Double  

Number of milliseconds since midnight 01 January 1970 UTC to the given date ignoring leap seconds.

Operators

==

public static func == (lhs: JSDate, rhs: JSDate) -> Bool  

<

public static func < (lhs: JSDate, rhs: JSDate) -> Bool