asp.net.ph

DateTimeFormatInfo.GetAllDateTimePatterns Method

System.Globalization Namespace   DateTimeFormatInfo Class


Returns the standard patterns in which DateTime values can be formatted.

Overload List

1. Returns all the standard patterns in which DateTime values can be formatted.

2. Returns all the standard patterns in which DateTime values can be formatted using the specified format character.


Example

The following example uses both versions of GetAllDateTimePatterns to fetch and print 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>
  C# VB

 Show me 

See Also

DateTimeFormatInfo Members 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