Formats a time using a given locale.

Text = SRP_Time("Format", Time, Format = "Short", Locale = "")

Returns

Formatted text.

Parameters

ParameterDescription
TimeA time in OI internal format. (REQUIRED)
FormatA custom or predefined format. (OPTIONAL)
LocaleA locale for culture specific formatting. (OPTIONAL)

Remarks

The "Format" service converts an OI time into human readable text, much like OConv. Unlike OConv, however, this service supports infinite formatting options and localization.

Auto Format

You can set Format to either "Short" or "Long". In either case, the Locale will determine the format. Here are some examples, all formatting the time 3:07:43pm:

LocaleShort FormatLong Format
en-US3:07 PM3:07:43 PM
es-ES15:0715:07:43
fr-FR15:0715:07:43

If you omit Format or set it to "", then "Short" will be used.

Custom Format

You can customize the format using a special syntax. You can use any characters in the Format, but 'H', 'h', 'M', 'm', 'S', 's', 'A', 'a', 'T', and 't' are reserved characters. Any other character is treated as a literal and is displayed as is. Thus, you may use literal characters in your format to prefix or suffix the date as you choose. If you need to use any reserved characters literally, then surround your literal text in single or double quotes. If you need to display quotes, place two of them side by side. The reserved characters are interpreted as follows:

Character(s)DisplaysExample using 1/14/2020 3:07:43pmExample using es-ES
hHour1515
hh2-digit hour1515
mMinute77
mm2-digit minute0707
sSecond4343
ss2-digit second4343
aa/ppp
aaam/pmpmpm
aaaa.m./p.m.p.m.p.m.
AA/PPP
AAAM/PMPMPM
AAAA.M./P.M.P.M.P.M.
tAbbreviated cultural am/pmpp
ttCultural am/pmPMp

As you can see in the table above, the Locale still affects the output, but only when your format requires it.

Here are some example time formats, all them for the time 3:07:43pm:

Format

en-USes-ESfr-FR
h:mm aaa3:17 p.m.
3:17 p.m.3:17 p.m.
h:mm:sstt3:17:43PM
3:17:43p3:17:43PM
hh:mm:ss15:17:43
15:17:43
15:17:43

Only uppercase letters are used in the examples here, but lowercase are supported as well. However, we recommend using lowercase for times because SRP_DateTime uses 'M' for months and 'm' for minutes.

Locale

The Locale parameter specifies the specific culture used to help render the final text. Omitting Locale or setting it "" causes the "Format" service to use the user's current Windows locale setting. If, however, you want to specify your own localization, set this parameter to a locale name.


Examples

// Create an OI time
Time = SRP_Time("Encode", 3, 7, 43)

// Format a time using the default format and the current locale
Text = SRP_Time("Format", Time)

// Format a time using the long format and the current locale
Text = SRP_Time("Format", Time, "Long")

// Format a time using the long format and the Spanish language
Text = SRP_Time("Format", Time, "Long", "es")

// Format a time using a custom format and the Spanish-MEXICAN language
Text = SRP_Time("Format", Time, "h:mm:ss tt", "es-MX")
  • No labels