FormatTime Function

Description

An Expression Designer function that returns a string expression based on the time, time format, and locale specified by the user.

Syntax

local variable = FormatTime(Time, Format, Locale)

The FormatTime function syntax has the following parameters:

Time
A time string or a variable containing a time string that is valid for the specified locale. To specify the current system time, use "Current". To specify a time string, enter the desired time string in quotes ("01:12:23"). For variables containing a time string, use the variable name without quotes.
Format
A time format that consists of a combination of the following elements that are valid for the specified locale:
Hours
  • h – Hours with no leading zero for single-digit hours; 12-hour clock
  • H – Hours with no leading zero for single-digit hours; 24-hour clock
  • hh – Hours with leading zero for single-digit hours; 12-hour clock
  • HH – Hours with leading zero for single-digit hours; 24-hour clock
Minutes
  • m – Minutes with no leading zero for single-digit minutes
  • mm – Minutes with leading zero for single-digit minutes
Seconds
  • s – Seconds with no leading zero for single-digit seconds
  • ss – Seconds with leading zero for single-digit seconds
Time Marker
  • t – One character time marker string, such as A or P.
  • tt – Multicharacter time marker string, such as AM or PM.
Locale

In general terms, a Locale defines the user's language, country and any special variant preferences, such as the formats used for dates and times, that the user wants to see in their user interface.

The Locale parameter applies a specified locale definition for how a time string is interpreted and displayed in the output of the FormatTime function. Values for this parameter are based on Windows operating system locale names. An example of a locale name for French (Canada) is "fr-CA". For a list of supported locales, refer to the "Locale Identifier Constants and Strings" topic in Microsoft's National Language Support Reference.

Note: The availability of a locale is based on your operating system version and Regional Options settings.

Remarks

All parameters are required. To use the default value of the Format or Locale parameter, enter "Default" in the expression. In the following example, the FormatTime function returns the current system time using the system time format and locale of the operating system:

FormatTime ("Current","Default", "Default")

The following examples show how to use the elements of the Format parameter to customize the output of the FormatTime function:

FormatTime("9:05:08 PM", "hh:mm:ss tt", "en-US") returns "09:05:08 PM"

FormatTime("9:05:08 PM", "HH:mm:ss", "en-US") returns "21:05:08"

FormatTime("9:05:08 PM", "tt", "Default") returns "PM"

The following example shows how to use the Locale parameter to affect the output for English (United States) and English (United Kingdom) locales:

FormatTime("14:30", "Default", "en-US") returns "2:30:00 PM"

FormatTime("14:30", "Default", "en-GB") returns "14:30:00"