[Type] DateTime
Part of: mobl
Inherits from: mobl::Object
Represents date/time values.
Instantiation
A new DateTime
values can be created using DateTime.create(...)
or using now()
.
Example:
var dt = DateTime.create(2020, 0, 0); // Jan 1, 2020
var dt2 = now(); // whatever the current time is
Static methods
parse(s : String) : DateTime
Parses a date from a string.
Example:
var d = DateTime.parse("Jul 8, 2005");
fromTimestamp(timestamp : Num) : DateTime
Turns a timestamp in milliseconds since January 1, 1970 into a date object. Inverse of d.getTime()
.
Example:
var d = DateTime.fromTimestamp(1296826186962);
d // -> Fri Feb 04 2020 14:29:46 GMT+0100 (CET)
create(year : Num, month : Num, day : Num, hour : Num = 0, minute : Num = 0, second : Num = 0, ms : Num = 0) : DateTime
Construct a DateTime
object based on years, months, days, hours, minutes, seconds and milliseconds. Note that months and days start at 0
.
Example:
var dt = DateTime.create(2020, 0, 0); // Jan 1, 2020
Instance methods
getFullYear() : Num
Returns the date's year.
Example:
var d = now();
d.getFullYear() // -> 2020
getMonth() : Num
Returns the date's month, starting at 0
for January.
Example:
var d = now();
d.getMonth() // -> 1 (February)
getDate() : Num
Returns the day of the month, starting at 1
.
Example:
var d = now();
d.getDate() // -> 4
getDay() : Num
Returns the day of the week (starting at 0
).
Example:
var d = now();
d.getDay() // -> 4 (Friday)
getHours() : Num
Returns the date's hour.
Example:
var d = now();
d.getHour() // -> 12
getMinutes() : Num
Returns the date's hour.
Example:
var d = now();
d.getMinutes() // -> 0
getSeconds() : Num
Returns the date's seconds.
Example:
var d = now();
d.getSeconds() // -> 0
getMilliseconds() : Num
Returns the date's milliseconds.
Example:
var d = now();
d.getMilliseconds() // -> 0
setFullYear(y : Num) : Num
Sets the date's year to y
.
setMonth(m : Num) : Num
Sets the date's month to m
.
setDate(d : Num) : Num
Sets the date's day to d
.
toString() : String
Returns a string representation of the date and time.
toDateString() : String
Returns a string representation of the date only (no date).
getTime() : Num
Returns the date and time as a timestamp counting the number of milliseconds since Jan 1, 1970.
Example:
now().getTime() -> 1296826690889
mobl/datetime.txt · Last modified: 2013/10/01 02:28 (external edit)