asp.net.ph

DateTimeFormatInfo Class

System.Globalization Namespace


Defines how DateTime values are formatted and displayed, depending on the culture.

DateTimeFormatInfo Class Members

Collapse   Constructors

Visibility Constructor Parameters
public DateTimeFormatInfo ( )

Collapse   Properties

Visibility Name Value Type Accessibility
public AbbreviatedDayNames String [ Get , Set ]
public AbbreviatedMonthGenitiveNames String [ Get , Set ]
public AbbreviatedMonthNames String [ Get , Set ]
public AMDesignator String [ Get , Set ]
public Calendar Calendar [ Get , Set ]
public CalendarWeekRule CalendarWeekRule [ Get , Set ]
public static CurrentInfo DateTimeFormatInfo [ Get ]
public DateSeparator String [ Get , Set ]
public DayNames String [ Get , Set ]
public FirstDayOfWeek DayOfWeek [ Get , Set ]
public FullDateTimePattern String [ Get , Set ]
public static InvariantInfo DateTimeFormatInfo [ Get ]
public IsReadOnly Boolean [ Get ]
public LongDatePattern String [ Get , Set ]
public LongTimePattern String [ Get , Set ]
public MonthDayPattern String [ Get , Set ]
public MonthGenitiveNames String [ Get , Set ]
public MonthNames String [ Get , Set ]
public NativeCalendarName String [ Get ]
public PMDesignator String [ Get , Set ]
public RFC1123Pattern String [ Get ]
public ShortDatePattern String [ Get , Set ]
public ShortestDayNames String [ Get , Set ]
public ShortTimePattern String [ Get , Set ]
public SortableDateTimePattern String [ Get ]
public TimeSeparator String [ Get , Set ]
public UniversalSortableDateTimePattern String [ Get ]
public YearMonthPattern String [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
public Clone ( ) Object
public GetAbbreviatedDayName ( DayOfWeek dayofweek ) String
public GetAbbreviatedEraName ( Int32 era ) String
public GetAbbreviatedMonthName ( Int32 month ) String
public GetAllDateTimePatterns ( ) String
public GetAllDateTimePatterns ( Char format ) String
public GetDayName ( DayOfWeek dayofweek ) String
public GetEra ( String eraName ) Int32
public GetEraName ( Int32 era ) String
public GetFormat ( Type formatType ) Object
public static GetInstance ( IFormatProvider provider ) DateTimeFormatInfo
public GetMonthName ( Int32 month ) String
public GetShortestDayName ( DayOfWeek dayOfWeek ) String
public static ReadOnly ( DateTimeFormatInfo dtfi ) DateTimeFormatInfo
public SetAllDateTimePatterns ( String patterns , Char format ) Void

Remarks

This class contains information, such as date patterns, time patterns, and AM/PM designators.

To create a DateTimeFormatInfo for a specific culture, create a CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat property. To create a DateTimeFormatInfo for the culture of the current thread, use the CurrentInfo property. To create a DateTimeFormatInfo for the invariant culture, use the InvariantInfo property for a read-only version, or use the DateTimeFormatInfo constructor for a writable version. It is not possible to create a DateTimeFormatInfo for a neutral culture.

The user might choose to override some of the values associated with the current culture of Windows through Regional and Language Options ( or Regional Options or Regional Settings ) in Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the CultureInfo.UseUserOverride property is set to true, the properties of the CultureInfo.DateTimeFormat instance, the CultureInfo.NumberFormat instance, and the CultureInfo.TextInfo instance are also retrieved from the user settings. If the user settings are incompatible with the culture associated with the CultureInfo ( for example, if the selected calendar is not one of the OptionalCalendars ), the results of the methods and the values of the properties are undefined.

DateTime values are formatted using standard or custom patterns stored in the properties of a DateTimeFormatInfo.

The standard patterns can be replaced with custom patterns by setting the associated properties of a writable DateTimeFormatInfo. To determine if a DateTimeFormatInfo is writable, use the IsReadOnly property.

The following table lists the standard format characters for each standard pattern and the associated DateTimeFormatInfo property that can be set to modify the standard pattern. The format characters are case-sensitive; for example, 'g' and 'G' represent slightly different patterns.

Format Character Associated Property/ Description Example Format Pattern ( en-US )
d ShortDatePattern MM/dd/yyyy
D LongDatePattern dddd, dd MMMM yyyy
f Full date and time ( long date and short time ) dddd, dd MMMM yyyy HH:mm
F FullDateTimePattern ( long date and long time ) dddd, dd MMMM yyyy HH:mm:ss
g General ( short date and short time ) MM/dd/yyyy HH:mm
G General ( short date and long time ) MM/dd/yyyy HH:mm:ss
m, M MonthDayPattern MMMM dd
r, R RFC1123Pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
s SortableDateTimePattern ( based on ISO 8601 ) using local time yyyy'-'MM'-'dd'T'HH':'mm':'ss
t ShortTimePattern HH:mm
T LongTimePattern HH:mm:ss
u UniversalSortableDateTimePattern using universal time yyyy'-'MM'-'dd HH':'mm':'ss'Z'
U Full date and time ( long date and long time ) using universal time dddd, dd MMMM yyyy HH:mm:ss
y, Y YearMonthPattern yyyy MMMM

The following table lists the patterns that can be combined to construct 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
d The day of the month. Single-digit days will not have a leading zero.
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.
dddd The full name of the day of the week, as defined in DayNames.
M The numeric month. Single-digit months will not have a leading zero.
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.
f The fraction of a second in single-digit precision. The remaining digits are truncated.
ff The fraction of a second in double-digit precision. The remaining digits are truncated.
fff The fraction of a second in three-digit precision. The remaining digits are truncated.
ffff The fraction of a second in four-digit precision. The remaining digits are truncated.
fffff The fraction of a second in five-digit precision. The remaining digits are truncated.
ffffff The fraction of a second in six-digit precision. The remaining digits are truncated.
fffffff The fraction of a second in seven-digit precision. The remaining digits are truncated.
t The first character in the AM/PM designator defined in AMDesignator or PMDesignator.
tt The AM/PM designator defined in AMDesignator or PMDesignator.
z The time zone offset ( "+" or "-" followed by the hour only ). Single-digit hours will not have a leading zero. For example, Pacific Standard Time is "-8".
zz The time zone offset ( "+" or "-" followed by the hour only ). Single-digit hours will have a leading zero. For example, Pacific Standard Time is "-08".
zzz The full time zone offset ( "+" or "-" followed by the hour and minutes ). Single-digit hours and minutes will have leading zeros. For example, Pacific Standard Time is "-08:00".
: The default time separator defined in TimeSeparator.
/ The default date separator defined in DateSeparator.
% c Where c is a format pattern if used alone. The "%" character can be omitted if the format pattern is combined with literal characters or other format patterns.
\ c Where c is any character. Displays the character literally. To display the backslash character, use "\\".

Only format patterns listed in the second table above can be used to create custom patterns; standard format characters listed in the first table cannot be used to create custom patterns. Custom patterns are at least two characters long; for example,

  • DateTime.ToString ( "d" ) returns the DateTime value; "d" is the standard short date pattern.
  • DateTime.ToString ( "%d" ) returns the day of the month; "%d" is a custom pattern.
  • DateTime.ToString ( "d " ) returns the day of the month followed by a white-space character; "d " is a custom pattern.

A DateTimeFormatInfo or a NumberFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures. For more information about the invariant culture, specific cultures, and neutral cultures, see the CultureInfo class.

This class implements the ICloneable interface to enable duplication of DateTimeFormatInfo objects. It also implements IFormatProvider to supply formatting information to applications.

See Also

DateTime   Calendar   CultureInfo Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph