This topic describes format specifiers that you can use in functions that convert date and time values to strings (these functions are provided by the Utilities plugin). The format specifiers are case-insensitive. If a format string is empty, TestComplete will use the c
specifier.
Format Specifiers
The following table lists specifiers that correspond to standard date and time formats. These formats are specified by the Regional Settings in the Windows Control Panel.
Specifier | Description | Example for English (USA) Culture |
---|---|---|
c | The date and time in the general format (if the value has no time part, formats date only). The date format is specified by the ShortDateFormat property; the time format - by the LongTimeFormat property. |
4/23/2007 10:39:55 AM |
ddddd | The date in the short date format specified by the ShortDateFormat property.
|
4/23/2007 |
dddddd | The date in the long date format specified by the LongDateFormat property.
|
Monday, April 23, 2007 |
t | The time in the short time format specified by the ShortTimeFormat property.
|
10:39 AM |
tt | The time in the long time format specified by the LongTimeFormat property.
|
10:39:55 AM |
If you need to get the date-time string in a specific format, use the following specifiers to construct a custom format string:
Specifier | Description |
---|---|
d | Day of a month as a number without the leading zero. |
dd | Day of a month as a number with the leading zero. |
ddd | Day of a week as an abbreviation (Sun, Mon, Tue, etc.) The short day names depend on the active regional settings on your computer. |
dddd | The full name of a day of a week (e.g. Sunday, Monday, Tuesday). The day names depend on the active regional settings on your computer. |
m | Month as an integer number without the leading zero. |
mm | Month as an integer number with the leading zero. |
mmm | Month as an abbreviation (e.g. Jan, Feb, Mar). The short month names depend on the active regional settings on your computer. |
mmmm | The full month name (January, February, March, etc.) The month names depend on the active regional settings on your computer. |
yy | Displays the year using the two digit year format. |
yyyy | Displays the year using the four digits year format. |
h | Hour without the leading zero (0-23). |
hh | Hour with the leading zero (00-23). |
n | Minute without the leading zero (0-59). |
nn | Minute with the leading zero (00-59). |
s | Second without the leading zero (0-59). |
ss | Second with the leading zero (00-59). |
z | Millisecond without the leading zero (0-999). |
zzz | Millisecond with the leading zero(s) (000-999). |
am/pm | Uses the 12-hour am/pm format for the time (Displays am for the time that is before the noon. Displays pm for the time that is after the noon). |
a/p | Similar to the am/pm specifier, but uses a and p instead of am and pm. |
ampm | Similar to the am/pm specifier. However, for the time before the noon it uses the suffix specified by the TimeAMString property. For the time after the noon uses the suffix specified by the TimePMString property. |
Note: |
The am/pm, a/p and ampm specifies have effect only if the formatting string contains either h or hh specifiers and they are located somewhere before the am/pm, a/m or ampm specifiers. |
"nnn" or 'nnn' | Inserts characters enclosed in single or double quotes into the resulting string. You can use this to add characters used as specifiers (such as d or m) into the string. |
Any other characters | do not affect formatting and are inserted in the formatted string as they are. |
Examples
Below you can find examples of custom format strings and the corresponding formatted date-time strings.
Format String | Result | Notes |
---|---|---|
Full date/time format (with long time) | ||
ddd, dd mmmm yyyy hh":"nn":"ss "GMT" | Mon, 23 April 2007 10:39:55 GMT | RFC1123 format |
yyyy-mm-dd"T"hh":"nn":"ss AMPM | 2007-04-23T10:39:55 AM | ISO 8601 format |
yyyy-mm-dd | 2007-04-23 | |
yyyy-mmm-dd | 2007-Apr-23 | |
dd.mm.yyyy | 23.04.2007 | |
dd mmm yyyy | 23 Apr 2007 | |
mmmm, yyyy | April, 2007 | Month of year |
mmmm dd | April 23 | Day of month |
ddd, mmm d, "'"yy | Mon, Apr 23, '07 | |
dd"rd of" mmmm, yyyy | 23rd of April, 2007 | |
hh "o'clock" AMPM | 10 o'clock AM | |
h:nn:ss.zzz | 21:48:50.832 |
See Also
Working With Dates
Working With Time
Utilities Object
DateTimeToString Method
FormatDateTime Method
GetFormatSettings Method