Provides culture-specific information about the format of date and time values.
public ref class DateTimeFormatInfo sealed : IFormatProvider
public ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider
public ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider, System::Runtime::Serialization::ISerializable
public sealed class DateTimeFormatInfo : IFormatProvider
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
[System.Serializable]
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider, System.Runtime.Serialization.ISerializable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
type DateTimeFormatInfo = class
interface IFormatProvider
type DateTimeFormatInfo = class
interface ICloneable
interface IFormatProvider
[<System.Serializable>]
type DateTimeFormatInfo = class
interface ICloneable
interface IFormatProvider
interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DateTimeFormatInfo = class
interface ICloneable
interface IFormatProvider
Public NotInheritable Class DateTimeFormatInfo
Implements IFormatProvider
Public NotInheritable Class DateTimeFormatInfo
Implements ICloneable, IFormatProvider
Public NotInheritable Class DateTimeFormatInfo
Implements ICloneable, IFormatProvider, ISerializable
The following example uses reflection to get the properties of the DateTimeFormatInfo object for the English (United States) culture. It displays the value of those properties that contain custom format strings and uses those strings to display formatted dates.
using System;
using System.Globalization;
using System.Reflection;
public class Example
{
public static void Main()
{
// Get the properties of an en-US DateTimeFormatInfo object.
DateTimeFormatInfo dtfi = CultureInfo.GetCultureInfo("en-US").DateTimeFormat;
Type typ = dtfi.GetType();
PropertyInfo[] props = typ.GetProperties();
DateTime value = new DateTime(2012, 5, 28, 11, 35, 0);
foreach (var prop in props) {
// Is this a format pattern-related property?
if (prop.Name.Contains("Pattern")) {
string fmt = prop.GetValue(dtfi, null).ToString();
Console.WriteLine("{0,-33} {1} \n{2,-37}Example: {3}\n",
prop.Name + ":", fmt, "",
value.ToString(fmt));
}
}
}
}
// The example displays the following output:
// FullDateTimePattern: dddd, MMMM dd, yyyy h:mm:ss tt
// Example: Monday, May 28, 2012 11:35:00 AM
//
// LongDatePattern: dddd, MMMM dd, yyyy
// Example: Monday, May 28, 2012
//
// LongTimePattern: h:mm:ss tt
// Example: 11:35:00 AM
//
// MonthDayPattern: MMMM dd
// Example: May 28
//
// RFC1123Pattern: ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
// Example: Mon, 28 May 2012 11:35:00 GMT
//
// ShortDatePattern: M/d/yyyy
// Example: 5/28/2012
//
// ShortTimePattern: h:mm tt
// Example: 11:35 AM
//
// SortableDateTimePattern: yyyy'-'MM'-'dd'T'HH':'mm':'ss
// Example: 2012-05-28T11:35:00
//
// UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z'
// Example: 2012-05-28 11:35:00Z
//
// YearMonthPattern: MMMM, yyyy
// Example: May, 2012
Imports System.Globalization
Imports System.Reflection
Module Example
Public Sub Main()
' Get the properties of an en-US DateTimeFormatInfo object.
Dim dtfi As DateTimeFormatInfo = CultureInfo.GetCultureInfo("en-US").DateTimeFormat
Dim typ As Type = dtfi.GetType()
Dim props() As PropertyInfo = typ.GetProperties()
Dim value As Date = #05/28/2012 11:35AM#
For Each prop In props
' Is this a format pattern-related property?
If prop.Name.Contains("Pattern") Then
Dim fmt As String = CStr(prop.GetValue(dtfi, Nothing))
Console.WriteLine("{0,-33} {1} {2}{3,-37}Example: {4}",
prop.Name + ":", fmt, vbCrLf, "",
value.ToString(fmt))
Console.WriteLine()
End If
Next
End Sub
End Module
' The example displays the following output:
' FullDateTimePattern: dddd, MMMM dd, yyyy h:mm:ss tt
' Example: Monday, May 28, 2012 11:35:00 AM
'
' LongDatePattern: dddd, MMMM dd, yyyy
' Example: Monday, May 28, 2012
'
' LongTimePattern: h:mm:ss tt
' Example: 11:35:00 AM
'
' MonthDayPattern: MMMM dd
' Example: May 28
'
' RFC1123Pattern: ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
' Example: Mon, 28 May 2012 11:35:00 GMT
'
' ShortDatePattern: M/d/yyyy
' Example: 5/28/2012
'
' ShortTimePattern: h:mm tt
' Example: 11:35 AM
'
' SortableDateTimePattern: yyyy'-'MM'-'dd'T'HH':'mm':'ss
' Example: 2012-05-28T11:35:00
'
' UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z'
' Example: 2012-05-28 11:35:00Z
'
' YearMonthPattern: MMMM, yyyy
' Example: May, 2012
For more information about this API, see Supplemental API remarks for DateTimeFormatInfo.
Constructors Properties AbbreviatedDayNamesGets or sets a one-dimensional array of type String containing the culture-specific abbreviated names of the days of the week.
AbbreviatedMonthGenitiveNamesGets or sets a string array of abbreviated month names associated with the current DateTimeFormatInfo object.
AbbreviatedMonthNamesGets or sets a one-dimensional string array that contains the culture-specific abbreviated names of the months.
AMDesignatorGets or sets the string designator for hours that are "ante meridiem" (before noon).
CalendarGets or sets the calendar to use for the current culture.
CalendarWeekRuleGets or sets a value that specifies which rule is used to determine the first calendar week of the year.
CurrentInfoGets a read-only DateTimeFormatInfo object that formats values based on the current culture.
DateSeparatorGets or sets the string that separates the components of a date, that is, the year, month, and day.
DayNamesGets or sets a one-dimensional string array that contains the culture-specific full names of the days of the week.
FirstDayOfWeekGets or sets the first day of the week.
FullDateTimePatternGets or sets the custom format string for a long date and long time value.
InvariantInfoGets the default read-only DateTimeFormatInfo object that is culture-independent (invariant).
IsReadOnlyGets a value indicating whether the DateTimeFormatInfo object is read-only.
LongDatePatternGets or sets the custom format string for a long date value.
LongTimePatternGets or sets the custom format string for a long time value.
MonthDayPatternGets or sets the custom format string for a month and day value.
MonthGenitiveNamesGets or sets a string array of month names associated with the current DateTimeFormatInfo object.
MonthNamesGets or sets a one-dimensional array of type String containing the culture-specific full names of the months.
NativeCalendarNameGets the native name of the calendar associated with the current DateTimeFormatInfo object.
PMDesignatorGets or sets the string designator for hours that are "post meridiem" (after noon).
RFC1123PatternGets the custom format string for a time value that is based on the Internet Engineering Task Force (IETF) Request for Comments (RFC) 1123 specification.
ShortDatePatternGets or sets the custom format string for a short date value.
ShortestDayNamesGets or sets a string array of the shortest unique abbreviated day names associated with the current DateTimeFormatInfo object.
ShortTimePatternGets or sets the custom format string for a short time value.
SortableDateTimePatternGets the custom format string for a sortable date and time value.
TimeSeparatorGets or sets the string that separates the components of time, that is, the hour, minutes, and seconds.
UniversalSortableDateTimePatternGets the custom format string for a universal, sortable date and time string, as defined by ISO 8601.
YearMonthPatternGets or sets the custom format string for a year and month value.
Methods Explicit Interface Implementations See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4