asp.net.ph

DateTime.GetDateTimeFormats Method ( Char )

System Namespace   DateTime Structure


Converts the value of this instance to all the string representations supported by the specified standard DateTime format specifier.

[ VB ]
<Serializable>
Overloads Public Function GetDateTimeFormats ( _
   ByVal format As Char _
) As String ( )

[ C# ]
[ Serializable ]
public string [ ] GetDateTimeFormats (
   char format
);

[ C++ ]
[ Serializable ]
public: String* GetDateTimeFormats (
   __wchar_t format
) __gc [ ];

[ JScript ]
public Serializable
function GetDateTimeFormats (
   format : Char
) : String [ ];

Parameters

format
A Unicode character containing a format specifier.

Return Value

A string array where each element is the representation of the value of this instance formatted with the format standard DateTime formatting specifier.

Remarks

Each element of the return value is formatted using information from the current culture. For more information about culture-specific formatting information for the current culture, see CultureInfo.CurrentCulture.

For more information about the standard formatting specifiers, see System.Globalization.DateTimeFormatInfo.

Example

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>
  C# VB

 Show me 

See Also

DateTime Members   DateTime.GetDateTimeFormats Overload List 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