3.2 KiB
3.2 KiB
getDateTime()
The getDateTime() command retrieves the current date and time, formats it according to a specified format, applies an optional time adjustment, and converts it to a specific time zone before storing the result in a target variable. It is useful for obtaining and manipulating the current date and time in different formats and time zones.
Parameters
- Format Type: var Description: A format string that defines how the resulting date and time should be presented. This string follows the date and time formatting conventions used in Python. Some of the most common symbols include: %Y : Year with four digits (e.g., 2024) %m : Month with two digits (01 to 12) %d : Day of the month with two digits (01 to 31) %H : Hour in 24-hour format (00 to 23) %M : Minutes (00 to 59) %S : Seconds (00 to 59) For example, the format "%Y-%m-%d %H:%M:%S" will present the date and time as 2024-08-25 14:30:00 . It can be a direct value or a variable containing the desired format.
- %Y : Year with four digits (e.g., 2024)
- %m : Month with two digits (01 to 12)
- %d : Day of the month with two digits (01 to 31)
- %H : Hour in 24-hour format (00 to 23)
- %M : Minutes (00 to 59)
- %S : Seconds (00 to 59)
- TimeDelta Type: var Description: An optional value representing a time adjustment (positive or negative) applied to the current date and time before conversion. This value can be provided directly or through a variable and is expressed in seconds.
- TimeZone Type: var Description: The time zone to which the date and time should be converted. This value can be a time zone identifier provided directly or through a variable. Some common time zones include: "UTC" : Coordinated Universal Time "America/New_York" : U.S. Eastern Time (EST/EDT) "America/Los_Angeles" : U.S. Pacific Time (PST/PDT) "Europe/London" : London Time (GMT/BST) "Europe/Madrid" : Madrid Time (CET/CEST) "Asia/Tokyo" : Tokyo Time (JST) "Australia/Sydney" : Sydney Time (AEST/AEDT) You can use any time zone recognized by the pytz library in Python, which includes most time zones worldwide.
- "UTC" : Coordinated Universal Time
- "America/New_York" : U.S. Eastern Time (EST/EDT)
- "America/Los_Angeles" : U.S. Pacific Time (PST/PDT)
- "Europe/London" : London Time (GMT/BST)
- "Europe/Madrid" : Madrid Time (CET/CEST)
- "Asia/Tokyo" : Tokyo Time (JST)
- "Australia/Sydney" : Sydney Time (AEST/AEDT)
- TargetVariable Type: var Description: The variable in which the resulting date and time from the operation will be stored. Unlike the other parameters, this must be a variable and not a direct value.
Usage Example
// Direct call with values:
getDateTime('%Y-%m-%d %H:%M:%S', 3600, 'UTC', currentTime)
// Call using variables:
format = '%Y-%m-%d %H:%M:%S'
adjustment = 3600
timeZone = 'America/New_York'
getDateTime(format, adjustment, timeZone, currentDateTime)
In the first example, the current date and time are retrieved, adjusted by 3600 seconds (1 hour), converted to UTC, and stored in the variable currentTime. In the second example, variables are used to define the format, time adjustment, and time zone, with the result stored in the currentDateTime variable.