Friday, November 7, 2008

Date Format Pattern

How often we use to format date and times ? I never had a chance put aside this informationthe right way. Maybe for lack of time or lazyness ... but this time I'll do it right once and for all !

So here is the tables with the parameters and description.

The table below displays a list of the standard format characters . The format characters are case-sensitive; for example, 'f' and 'F' represent different patterns.

Format Character

Associated Property/ Description
d ShortDatePattern
D LongDatePattern
f Full Date and time (long Date and short time)
F FullDateTimePattern (long Date and long time)
g General (short Date and short time)
G General (short Date and long time)
m, M MonthDayPattern
r, R RFC1123Pattern
s SortableDateTimePattern (based on ISO 8601) using local time
t ShortTimePattern
T LongTimePattern
u UniversalSortableDateTimePattern using the format for universal time display
U Full date and time (long date and long time) using universal time

The table below shows a list of patterns that can be combined to create custom patterns. The patterns are case-sensitive; for example, "MM" is recognized, but "mm" is not. If the custom pattern contains white-space characters or characters enclosed in single quotation marks, the output string will also contain those characters. Characters not defined as part of a format pattern or as format characters are reproduced literally.


Format Pattern

Description

dd The day of the month. Single-digit days will have a leading zero.
ddd The abbreviated name of the day of the week, as defined in AbbreviatedDayNames.
M The full name of the day of the week, as defined in DayNames.
MM The numeric month. Single-digit months will have a leading zero.
MMM The abbreviated name of the month, as defined in AbbreviatedMonthNames.
MMMM The full name of the month, as defined in MonthNames.
y The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero.
yy The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero.
yyyy The year in four digits, including the century.
gg The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string.
h The hour in a 12-hour clock. Single-digit hours will not have a leading zero.
hh The hour in a 12-hour clock. Single-digit hours will have a leading zero.
H The hour in a 24-hour clock. Single-digit hours will not have a leading zero.
HH The hour in a 24-hour clock. Single-digit hours will have a leading zero.
m The minute. Single-digit minutes will not have a leading zero.
mm The minute. Single-digit minutes will have a leading zero.
s The second. Single-digit seconds will not have a leading zero.
ss The second. Single-digit seconds will have a leading zero.
t The first character in the AM/PM designator defined in AMDesignator or PMDesignator, if any.
tt The AM/PM designator defined in AMDesignator or PMDesignator, if any.

No comments: