System.Globalization Namespace DateTimeFormatInfo Class
Returns all the standard patterns in which DateTime values can be formatted using the specified format character.
[ VB ]
Overloads Public Function GetAllDateTimePatterns ( _
ByVal format As Char _
) As String ( )
[ C# ]
public string [ ] GetAllDateTimePatterns (
char format
);
[ C++ ]
public: String* GetAllDateTimePatterns (
__wchar_t format
) __gc [ ];
[ JScript ]
function GetAllDateTimePatterns (
format : Char
) : String [ ];
- format
- A standard format character.
An array containing the standard patterns in which DateTime values can be formatted using the specified format character.
Exception Type |
Condition |
ArgumentException |
format is not a valid standard format character. |
See the summary page of the DateTimeFormatInfo class for a list of the standard format characters and their associated patterns.
The following code example gets and prints the DateTime patterns for the current calendar.
<script language="C#" runat="server">
DateTime now;
string html;
public void Page_Load ( Object src, EventArgs e ) {
// Create a new DateTimeFormatinfo instance.
DateTimeFormatInfo myDtfi = new DateTimeFormatInfo ( );
// Create a new DateTime object
now = DateTime.Now;
// Get and print all the patterns.
String [ ] myPatterns = myDtfi.GetAllDateTimePatterns ( );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>All the patterns:</th></tr>";
printValues ( myPatterns );
// Get and print the patterns associated with some of the format characters.
myPatterns = myDtfi.GetAllDateTimePatterns ( 'd' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'd' ) :</th></tr>";
printValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'D' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'D' ) :</th></tr>";
printValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'f' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'f' ) :</th></tr>";
printValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'F' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'F' ) :</th></tr>";
printValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'r' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'r' ) :</th></tr>";
printValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'R' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'R' ) :</th></tr>";
printValues ( myPatterns );
}
void printValues ( String [ ] myArray ) {
int i = 0;
foreach ( String s in myArray ) {
html += "<td>" + i++ + "</td>";
html += "<td>" + s + "</td>";
html += "<td>" + now.ToString ( s ) + "</td></tr>";
}
html += "</table><br>";
}
</script>
<script language="VB" runat="server">
Dim now As DateTime
Dim html As String
Public Sub Page_Load ( sender As [Object], e As EventArgs )
' Create a new DateTimeFormatinfo instance.
Dim myDtfi As New DateTimeFormatInfo ( )
' Create a new DateTime object
now = DateTime.Now
' Get and print all the patterns.
Dim myPatterns As [String] ( ) = myDtfi.GetAllDateTimePatterns ( )
html += "<table align='center' class='data' width=80% cellspacing=1>"
html += "<tr><th colspan=3>All the patterns:</th></tr>"
printValues ( myPatterns )
' Get and print the patterns associated with some of the format characters.
myPatterns = myDtfi.GetAllDateTimePatterns ( 'd' )
html += "<table align='center' class='data' width=80% cellspacing=1>"
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'd' ) :</th></tr>"
printValues ( myPatterns )
myPatterns = myDtfi.GetAllDateTimePatterns ( 'D' )
html += "<table align='center' class='data' width=80% cellspacing=1>"
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'D' ) :</th></tr>"
printValues ( myPatterns )
myPatterns = myDtfi.GetAllDateTimePatterns ( 'f' )
html += "<table align='center' class='data' width=80% cellspacing=1>"
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'f' ) :</th></tr>"
printValues ( myPatterns )
myPatterns = myDtfi.GetAllDateTimePatterns ( 'F' )
html += "<table align='center' class='data' width=80% cellspacing=1>"
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'F' ) :</th></tr>"
printValues ( myPatterns )
myPatterns = myDtfi.GetAllDateTimePatterns ( 'r' )
html += "<table align='center' class='data' width=80% cellspacing=1>"
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'r' ) :</th></tr>"
printValues ( myPatterns )
myPatterns = myDtfi.GetAllDateTimePatterns ( 'R' )
html += "<table align='center' class='data' width=80% cellspacing=1>"
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'R' ) :</th></tr>"
printValues ( myPatterns )
End Sub 'Page_Load
Sub printValues ( myArray ( ) As [String] )
Dim i As Integer = 0
Dim s As [String]
For Each s In myArray
html += "<td>" + i + 1 + "</td>"
html += "<td>" + s + "</td>"
html += "<td>" + now.ToString ( s ) + "</td></tr>"
Next s
html += "</table><br>"
End Sub 'printValues
</script> |
|
C# |
VB |
Show me
DateTimeFormatInfo Members DateTimeFormatInfo.GetAllDateTimePatterns Overload List