System Namespace DateTime Structure
Converts the value of this instance to all the string representations supported by the specified standard DateTime format specifier and culture-specific formatting information.
[ VB ]
<Serializable>
Overloads Public Function GetDateTimeFormats ( _
ByVal format As Char, _
ByVal provider As IFormatProvider _
) As String ( )
[ C# ]
[ Serializable ]
public string [ ] GetDateTimeFormats (
char format,
IFormatProvider provider
);
[ C++ ]
[ Serializable ]
public: String* GetDateTimeFormats (
__wchar_t format,
IFormatProvider* provider
) __gc [ ];
[ JScript ]
public Serializable
function GetDateTimeFormats (
format : Char,
provider : IFormatProvider
) : String [ ];
- format
- A Unicode character containing a format specifier.
- provider
- An IFormatProvider that supplies culture-specific formatting information about this instance.
A string array where each element is the representation of the value of this instance formatted with one of the standard DateTime formatting specifiers.
Each element of the return value is formatted using culture-specific information supplied by provider.
For more information about the standard formatting specifiers, see System.Globalization.DateTimeFormatInfo.
The below code snippet demonstrates using the GetDateTimeFormats method.
<script language="C#" runat="server">
string html;
public void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
CultureInfo [ ] cultures = CultureInfo.GetCultures ( CultureTypes.SpecificCultures );
foreach ( CultureInfo c in cultures ) {
culturesSelect.Items.Add ( c.DisplayName );
culturesSelect.Items.FindByText ( c.DisplayName ).Value = c.Name;
}
}
// write headers
...
DateTime now = DateTime.Now;
IFormatProvider culture = new CultureInfo ( culturesSelect.SelectedItem.Value );
string [ ] nowFormats = now.GetDateTimeFormats ( culture );
// list all DateTime formats for given culture
int i = 0;
foreach ( string format in nowFormats ) {
html += "<tr>";
html += "<td>" + i ++ + "</td>";
html += "<td>" + format + "</td>";
html += "</tr>";
}
html += "</table>";
}
</script>
<script language="VB" runat="server">
Dim html As String
Public Sub Page_Load ( src As Object, e As EventArgs )
If Not IsPostBack Then
Dim cultures As CultureInfo ( ) = CultureInfo.GetCultures ( CultureTypes.SpecificCultures )
Dim c As CultureInfo
For Each c In cultures
culturesSelect.Items.Add ( c.DisplayName )
culturesSelect.Items.FindByText ( c.DisplayName ).Value = c.Name
Next c
End If
' write headers
...
Dim now As DateTime = DateTime.Now
Dim culture = New CultureInfo ( culturesSelect.SelectedItem.Value )
Dim nowFormats As String ( ) = now.GetDateTimeFormats ( culture )
' list all DateTime formats for given culture
Dim i As Integer = 0
Dim format As String
For Each format In nowFormats
html += "<tr>"
html += "<td>" & i + i & "</td>"
html += "<td>" & format & "</td>"
html += "</tr>"
Next format
html += "</table>"
End Sub
</script> |
|
C# |
VB |
Show me
DateTime Members DateTime.GetDateTimeFormats Overload List