Download PDF Vol. II - Software Products Library

Transcript
System Time Operations
27.6 Date/Time Formatting Routines
Input Format String
The input format string used to define the input date/time format must contain
at least the first seven of the following eight fields:
•
Month (either alphabetic or numeric)
•
Day of the month (numeric)
•
Year (from 1 to 4 digits)
•
Hour (12- or 24-hour clock)
•
Minute of the hour
•
Second of the minute
•
Fractional seconds
•
Meridiem indicator (required for 12-hour clock; illegal for 24-hour clock)
If the input format string specifies a 24-hour clock, the string contains only the
first seven fields in the preceding list. If a 12-hour clock is specified, the eighth
field (the meridiem indicator) is required.
The format string fields must appear in two groups: one for date and one for time
(date and time fields cannot be intermixed within a group). For the input format,
alphabetic case distinctions and abbreviation-specific codes have no significance.
For example, the following format string specifies that the month name will be
uppercase and spelled out in full:
!MAU !DD, !Y4 !H02:!M0:!S0:!C2 !MIU
If the input string corresponding to this format string contains a month name
that is abbreviated and lowercase, the parse of the input string still works
correctly. For example:
feb 25, 1988 04:39:02:55 am
If this input string is entered, the parse still recognizes ‘‘feb’’ as the month name
and ‘‘am’’ as the meridiem indicator, even though the format string specified both
of these fields as uppercase, and the month name as unabbreviated.
Punctuation in the Format and Input Strings
One important aspect to consider when formatting date/time input strings is
punctuation. The punctuation referred to here is the characters that separate the
various date/time fields or the date and time groups. Punctuation in these strings
is important because it is used as an outline for the parser, allowing the parser to
synchronize the input fields to the format fields.
There are three distinct classes of punctuation:
•
None
Although it is common for no punctuation to begin or end an input format
string, you can specify a date/time format that also has no punctuation
between the fields or groups of the format string. If this is the case, the
corresponding input string must not have any punctuation between the
respective fields or groups, although white space (see the next item in this
list) may appear at the beginning or end of the input string.
System Time Operations 27–27