DateTime
Package: Libraries.System · Inherits from: Libraries.Language.Object
The DateTime class is used to gather information about date and time on the system, or from a specified date/time. On creation, this object will return information pertaining to the current date and time as reported by the system. This class can also be used to gather information about a different date and time using the standard epoch time and the SetEpochTime() action. If SetEpochTime() is not called, information about the current date and time will be returned by the various functions.
Example Code
use Libraries.System.DateTime
class Main
action main
DateTime datetime
// Print the current date and time.
output datetime:GetMonth() + " " + datetime:GetDayOfMonth() + ", " + datetime:GetYear() + " " datetime:GetHour() + ":" + datetime:GetMinutes()
end
Actions
AddDays(integer days)
Parameters
daysinteger
AddHours(integer hours)
Parameters
hoursinteger
AddMinutes(integer minutes)
Parameters
minutesinteger
AddMonths(integer months)
Parameters
monthsinteger
AddSeconds(integer seconds)
Parameters
secondsinteger
AddWeeks(integer weeks)
Parameters
weeksinteger
AddYears(integer years)
Parameters
yearsinteger
Compare(Libraries.Language.Object object)
Parameters
objectLibraries.Language.Object
Returns
integer
DateToText()
Returns
text
GetDayDifference(Libraries.System.DateTime time)
Parameters
Returns
number
GetDayOfMonth()
This action returns the day of the month represented by this DateTime object. The day is in the range 1 to 31, inclusive.
Returns
integer: the day of the month
Example
DateTime datetime
output datetime:GetDayOfMonth()
GetDayOfWeek()
This action returns the day of the week represented by this DateTime object. The day is in the range 1 to 7, inclusive.
Returns
integer: the day of the week
Example
DateTime datetime
output datetime:GetDayOfWeek()
GetDayOfWeekName()
Returns
text
GetEpochTime()
This action returns the elapsed milliseconds since the epoch, January 1, 1970 00:00:00 GMT, as reported by the system. This time can be used to store a date and use it at a later time to retrieve information such as the hour. This action will always return the current epoch time, regardless of whether or not SetEpochTime() has been called.
Returns
number: Returns the elapsed time since the epoch as reported by the system.
Example
DateTime datetime
output datetime:GetEpochTime()
GetHour()
This action returns the hour represented by this DateTime object. The hour is in the range 0 to 23, where 0-12 represent the times 12 AM to 12 PM, and 13-23 represent 1 PM to 11 PM.
Returns
integer: the hour
Example
DateTime datetime
output datetime:GetHour()
GetHourDifference(Libraries.System.DateTime time)
Parameters
Returns
number
GetMillisecondDifference(Libraries.System.DateTime time)
Parameters
Returns
number
GetMinute()
This action returns the minute represented by this DateTime object. The minute is in the range 0 to 59, inclusive.
Returns
integer: the minute
Example
DateTime datetime
output datetime:GetMinute()
GetMinuteDifference(Libraries.System.DateTime time)
Parameters
Returns
number
GetMonth()
This action returns the month represented by this DateTime object. The month is in the range 1 to 12, inclusive.
Returns
integer: the month
Example
DateTime datetime
output datetime:GetMonth()
GetMonthDifference(Libraries.System.DateTime time)
Parameters
Returns
number
GetMonthName()
Returns
text
GetSecond()
This action returns the second represented by this DateTime object. The second is in the range 0 to 59, inclusive.
Returns
integer: the second
Example
DateTime datetime
output datetime:GetSecond()
GetSecondDifference(Libraries.System.DateTime time)
Parameters
Returns
number
GetShortDayofWeekName()
Returns
text
GetShortMonthName()
Returns
text
GetTimeZone()
This action returns the timezone of the system. The timezone is reported as an offset of UTC. For example, Central Standard Time in the United States is UTC - 6.
Returns
integer: the timezone offset from UTC.
Example
DateTime datetime
output datetime:GetTimeZone()
GetTimestamp()
Returns
text
GetYear()
This action returns the year represented by this DateTime object.
Returns
integer: the year
Example
DateTime datetime
output datetime:GetYear()
IsAfter(Libraries.System.DateTime time)
Parameters
Returns
boolean
IsBefore(Libraries.System.DateTime time)
Parameters
Returns
boolean
IsDaylightSavings()
This action returns whether or not the current system is observing daylight savings time.
Returns
boolean: whether or no daylight savings time is being observed
Example
DateTime datetime
boolean dst = datetime:IsDaylightSavings()
if dst
output "Spring forward"
else
output "Fall back"
end
Now()
Returns
number
ParseAmericanDate(text date)
Parameters
datetext
ParseDate(text date)
Parameters
datetext
ParseTime(text time, boolean keepDate)
Parameters
timetextkeepDateboolean
ParseTime(text time)
Parameters
timetext
ParseTimestamp(text timestamp)
Parameters
timestamptext
SetEpochTime(number epochTime)
This action sets the date/time to be represented by this DateTime instance to the specified epochTime value. Once this function is called, this DateTime instance cannot be used to get the current date/time.
Parameters
epochTimenumber: - the number of milliseconds that have elapsed since the epoch, returned by GetEpochTime().
Example
DateTime datetime
// Set this instance to the exact time of the epoch.
datetime:SetEpochTime(0)
output datetime:GetMonth() // will return 1 for January
SetTimeZone(integer timeZoneOffset)
This action sets the time zone offset to be used when returning various date/time information to the user.
Parameters
timeZoneOffsetinteger
Example
DateTime datetime
datetime:SetTimeZone(0) // set time zone to UTC.
output "The current UTC hour is " + datetime:GetHour()
SubtractDays(integer days)
Parameters
daysinteger
SubtractHours(integer hours)
Parameters
hoursinteger
SubtractMinutes(integer minutes)
Parameters
minutesinteger
SubtractMonths(integer months)
Parameters
monthsinteger
SubtractSeconds(integer seconds)
Parameters
secondsinteger
SubtractWeeks(integer weeks)
Parameters
weeksinteger
SubtractYears(integer years)
Parameters
yearsinteger
TimeToText()
Returns
text
ToText()
Returns
text