The DateTime class provides a basic structure for date and time related information. DateTime instances can be created with

DateTime handles date and time information in UTC.

Static methods

staticfromString(s:String):DateTime

Creates a DateTime from the formatted string s. The only accepted format is "YYYY-mm-ddTHH:MM:SS+00:00".

staticnow():DateTime

Creates a date representing the current UTC time.

Constructor

new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int)

Creates a new date object from the given arguments. The behaviour of a DateTime instance is only consistent across platforms if the arguments describe a valid date.

  • month: 0 to 11 (note that this is zero-based)
  • day: 1 to 31
  • hour: 0 to 23
  • min: 0 to 59
  • sec: 0 to 59

Methods

compare(other:DateTime):Int

Compares this DateTime with the given one, and returns the difference between both dates in seconds. A positive value means the this represents a later date, while a negative value means that this is an early date. If the function returns 0, it means both objects represent the same date with precision of seconds.

Parameters:

other

The DateTime we want to compare this to.

Returns:

Int

equals(other:DateTime):Bool

Indicates if the date in this is equal to the one in other. It is the same as doing this.compare(other) == 0.

Parameters:

other

The DateTime we want to compare this to.

Returns:

Bool

getDay():Int

Returns the day of this DateTime (1-31 range) in UTC.

getHours():Int

Returns the hours of this DateTime (0-23 range) in UTC.

getMinutes():Int

Returns the minutes of this DateTime (0-59 range) in UTC.

getMonth():Int

Returns the month of this DateTime (0-11 range) in UTC. Note that the month number is zero-based.

getSeconds():Int

Returns the seconds of this DateTime (0-59 range) in UTC.

getTimestamp():Float

Returns the timestamp in seconds of this DateTime. The fractional part contains at least milliseconds accuracy, so you can multiply by 1000 and cast to int if you need an integer timestamp. A timestamp is defined as the number of milliseconds elapsed since 1st January 1970 UTC.

Returns:

Float The timestamp in seconds.

getYear():Int

Returns the year of this DateTime (4 digits) in UTC.

isBetweenDates(first:DateTime, last:DateTime):Bool

toString():String

Returns a string representation of this DateTime in UTC using the standard format YYYY-mm-ddTHH:MM:SS+00:00.