<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Globalization" %>
<html>
<head>
<title>Date and Time Format Patterns</title>
<link rel="stylesheet" href="/aspxtreme/shared/netdemos.css">
<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>";
showValues ( myPatterns );
// Get and print the pattern(s) 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>";
showValues ( 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>";
showValues ( 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>";
showValues ( 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>";
showValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'g' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'g' ) :</th></tr>";
showValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'G' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'G' ) :</th></tr>";
showValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'm' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'm' ) :</th></tr>";
showValues ( 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>";
showValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 's' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 's' ) :</th></tr>";
showValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'u' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'u' ) :</th></tr>";
showValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'U' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'U' ) :</th></tr>";
showValues ( myPatterns );
myPatterns = myDtfi.GetAllDateTimePatterns ( 'y' );
html += "<table align='center' class='data' width=80% cellspacing=1>";
html += "<tr><th colspan=3>The patterns for DateTime.ToString ( 'y' ) :</th></tr>";
showValues ( myPatterns );
}
void showValues ( 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>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h3>Date and Time Format Patterns</h3></div>
<hr size=1 width=90%>
<p><%= html %></p>
<hr size=1 width=90%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>