The DateTime class provides a basic structure for date and time related information. DateTime instances can be created with
new DateTime()
for a specific date,DateTime.now()
to obtain information about the current time, orDateTime.fromString()
to parse from a string.
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"
.
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 |
---|
Returns:
Int
getMonth():Int
Returns the month of this
DateTime (0-11 range) in UTC.
Note that the month number is zero-based.
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.
toString():String
Returns a string representation of this
DateTime in UTC
using the standard format YYYY-mm-ddTHH:MM:SS+00:00
.