User-Defined Date/Time Formats (Format Function)
The following table shows characters you can use to create user-defined date/time formats. Unlike in previous versions of Visual Basic, these format characters are case-sensitive.
Character | Description |
---|---|
(:) |
Time separator. In some locales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system's LocaleID value. |
(/) |
Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your locale. |
(%) |
Used to indicate that the following character should be read as a single-letter format without regard to any trailing letters. Also used to indicate that a single-letter format is read as a user-defined format. See below for further details. |
d |
Displays the day as a number without a leading zero (for example, |
dd |
Displays the day as a number with a leading zero (for example, |
ddd |
Displays the day as an abbreviation (for example, |
dddd |
Displays the day as a full name (for example, |
M |
Displays the month as a number without a leading zero (for example, January is represented as |
MM |
Displays the month as a number with a leading zero (for example, |
MMM |
Displays the month as an abbreviation (for example, |
MMMM |
Displays the month as a full month name (for example, |
gg |
Displays the period/era string (for example, |
h |
Displays the hour as a number without leading zeros using the 12-hour clock (for example, |
hh |
Displays the hour as a number with leading zeros using the 12-hour clock (for example, |
H |
Displays the hour as a number without leading zeros using the 24-hour clock (for example, |
HH |
Displays the hour as a number with leading zeros using the 24-hour clock (for example, |
m |
Displays the minute as a number without leading zeros (for example, |
mm |
Displays the minute as a number with leading zeros (for example, |
s |
Displays the second as a number without leading zeros (for example, |
ss |
Displays the second as a number with leading zeros (for example, |
F |
Displays fractions of seconds. For example ff will display hundredths of seconds, whereas ffff will display ten-thousandths of seconds. You may use up to seven f symbols in your user-defined format. Use %f if this is the only character in your user-defined numeric format. |
T |
Uses the 12-hour clock and displays an uppercase |
tt |
For locales that use a 12-hour clock, displays an uppercase For locales that use a 24-hour clock, displays nothing. |
y |
Displays the year number (0-9) without leading zeros. Use %y if this is the only character in your user-defined numeric format. |
yy |
Displays the year in two-digit numeric format with a leading zero, if applicable. |
yyy |
Displays the year in four-digit numeric format. |
yyyy |
Displays the year in four-digit numeric format. |
z |
Displays the timezone offset without a leading zero (for example, |
zz |
Displays the timezone offset with a leading zero (for example, |
zzz |
Displays the full timezone offset (for example, |
Example
The following are examples of user-defined date and time formats for December 7, 1958, 8:50 PM, 35 seconds
:
Format | Displays |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Requirements
Namespace: Microsoft.VisualBasic
Module: Strings
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
See Also
Reference
String Manipulation Summary
Conversion Summary
Format Function
Predefined Date/Time Formats (Format Function)
User-Defined Numeric Formats (Format Function)