DateTime may refer to:
DateTime data type
HSL provides for variables that represent discrete moments in time through the DateTime data type. This helps implementers avoid issues of using integers that count the number of seconds that have passed since some well-defined start date. In conjunction with the DateTime data type, HSL also has a TimeInterval data type that represents a span of time.
The following demonstrates how to store the current date and time in a variable:
timestamp as DateTime = SYSTEM.TIME.NOW
Ideally you would store your timestamp on a node's field for future use:
myNode.timestamp = SYSTEM.TIME.NOW
Later on, you can then use that stored DateTime to calculate elapsed time, by subtracting it from the current time:
elapsedTime as TimeInterval = SYSTEM.TIME.NOW - myNode.timestamp
You can also add/subtract TimeInterval values to/from DateTime values in order to calculate past and future dates (note that in the following example,
72:00:00.0 is a literal TimeInterval value representing 72 hours):
expirationDate as DateTime = SYSTEM.TIME.NOW + 72:00:00.0
DateTime values auto-convert to String values with the format
mm/dd/yyyy hh:mm:ss. So the following code:
MsgPlayer( account, "", SYSTEM.TIME.NOW )
would display as something like:
DateTime has a variety of subfields that may be accessed via dot notation, allowing easy access to its component values. These are:
second as Integer // DateTime values are only accurate to whole seconds minute as Integer hour as Integer // military format, so 13 represents 1pm, 14 is 2pm, etc. month as Integer dayOfMonth as Integer year as Integer monthString as String // e.g., "March" dayOfWeek as String // e.g., "Tuesday"
Note that access to subfields is read-only.
Sometimes you need to create a DateTime variable from user input or other sources. The following external function provides for this, and is available to both client and server scripts.
external function DateTime( date as Integer, time as TimeInterval ) as DateTime
This function allows you to construct a DateTime variable from an integer representing the date, and a TimeInterval representing the
time passed since midnight. The
date must be in the format
yyyymmdd, so for example the following code:
alarm as DateTime = DateTime( 20060920, 14:00:00 ) println( alarm + " (" + alarm.dayOfWeek + ")" )
would print to the console:
SCRIPT[ScriptName]:09/20/2006 14:00:00 (Wednesday)
It is also possible to set a DateTime from a properly formatted string:
myDate as DateTime = "09/20/2006 14:00:00"