time Formats
Specifying the format of a time field that is passed as a parameter to a conversion.
Four conversions, string_from_time, ustring_from_time, time_from_string, and ustring_from_time, take as a parameter of the conversion a time format or a time uformat. These formats are described below. The default format of the time contained in the string is hh:mm:ss.
time Uformat
The time uformat date format provides support for international components in time fields. It's syntax is:
String % macroString % macroString % macroString
where %
macro is
a time formatting macro such as %hh for a two-digit hour. See time Format below for a description of the
time format macros. Only the String components of time uformat can
include multi-byte Unicode characters.
time Format
The string_from_time and time_from_string conversions take a format as a parameter of the conversion. The default format of the time in the string is hh:mm:ss. However, you can specify an optional format string defining the time format of the string field. The format string must contain a specification for hours, minutes, and seconds.
Tag | Variable width availability | Description | Value range | Options |
---|---|---|---|---|
%h | import | Hour (24), variable width | 0...23 | s |
%hh | Hour (24), fixed width | 0...23 | s | |
%H | import | Hour (12), variable width | 1...12 | s |
%HH | Hour (12), fixed width | 01...12 | s | |
%n | import | Minutes, variable width | 0...59 | s |
%nn | Minutes, fixed width | 0...59 | s | |
%s | import | Seconds, variable width | 0...59 | s |
%ss | Seconds, fixed width | 0...59 | s | |
%s.N | import | Seconds + fraction (N = 0...6) | – | s, c, C |
%ss.N | Seconds + fraction (N = 0...6) | – | s, c, C | |
%SSS | with v option | Milliseconds | 0...999 | s, v |
%SSSSSS | with v option | Microseconds | 0...999999 | s, v |
%aa | German | am/pm marker, locale specific | am, pm | u, w |
By default, the format of the time contained in the string is %hh:%nn:%ss. However, you can specify a format string defining the format of the string field.
You must prefix each component of the format string with the percent symbol. Separate the string's components with any character except the percent sign (%).
Where indicated the tags can represent variable-fields on import, export, or both. Variable-width date elements can omit leading zeroes without causing errors.
- s
- Specify this option to allow leading spaces in time formats. The s option is specified in the form:
- v
- Use this option in conjunction with the %SSS or %SSSSSS tags to represent milliseconds or microseconds in variable-width format. So the time property:
- u
- Use this option to render the am/pm text in uppercase on output.
- w
- Use this option to render the am/pm text in lowercase on output.
- c
- Specify this option to use a comma as the decimal separator in the %ss.N tag.
- C
- Specify this option to use a period as the decimal separator in the %ss.N tag.
The locale for determining the setting of the am/pm string and the default decimal separator can be controlled through the locale tag. This has the format:
%(L,'locale')
Where locale specifies the locale to be set using the language_COUNTRY.variant naming convention supported by ICU. The default locale for am/pm string and separators markers is English unless overridden by a %L tag or the APT_IMPEXP_LOCALE environment variable (the tag takes precedence over the environment variable if both are set).
Use the locale tag in conjunction with your time format, for example:
%L('es')%HH:%nn %aaSpecifies the Spanish locale.
Element | Numeric format tags | Text format tags | Requires | Incompatible with |
---|---|---|---|---|
hour | %hh, %h, %HH, %H | - | - | - |
am/pm marker | - | %aa | hour (%HH) | hour (%hh) |
minute | %nn, %n | - | - | - |
second | %ss, %s | - | - | - |
fraction of a second | %ss.N, %s.N, %SSS, %SSSSSS | - | - | - |
Tag | Escape sequence |
---|---|
%% | literal percent sign |
\% | literal percent sign |
\n | newline |
\t | horizontal tab |
\\ | single backslash |
Converting Time Fields to Integers Example
The following figure shows the conversion of time field to two 8-bit integers, where:
- The hours_from_time conversion specification extracts the hours portion of a time field and writes it to an 8-bit integer
- The minutes_from_time conversion specification extracts the minutes portion of a time field and writes it to an 8-bit integer.
The following osh code converts the hours portion of tField to the int8 hoursField and the minutes portion to the int8 minField:
modify 'hoursField = hours_from_time(tField);
minField = minutes_from_time(tField);'