.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> DateTime >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Datetime formats

Posted By:Athira Sreejith       Posted Date: January 02, 2009    Points: 10    Category: DateTime    URL: http://www.dotnetspark.com  
 

This function will give you all DateTime - Standarad as well as custom Formats.
Based on the radiobutton selection (i.e. standarad/custom) values will be displayed


private void LoadDateTimeFormats()
{
DateTime dtmNow = DateTime.Now;

StringBuilder sb = new StringBuilder();

strCultureValue = cboCultureInfoDateTime.SelectedValue.ToString();

Thread.CurrentThread.CurrentCulture = new CultureInfo(strCultureValue);

sb.Append("When using " + strCultureValue + " CultureInfo, today's date and time will format follows:");

sb.Append(crlf);

sb.Append(crlf);

if (optStandardDateTime.Checked)
{
sb.Append(dtmNow.ToString("d"));
sb.Append(" [Short date pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("D"));
sb.Append(" [Long date pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("t"));
sb.Append(" [Short time pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("T"));
sb.Append(" [Long time pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("F"));
sb.Append(" [Full date/time pattern (long)]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("f"));
sb.Append(" [Full date/time pattern (short)]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("G"));
sb.Append(" [General date/time pattern (long)]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("g"));
sb.Append(" [General date/time pattern (short)]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("M"));
sb.Append(" [Month day pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("R"));
sb.Append(" [RFC1123 pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("s"));
sb.Append(" [Sortable date/time pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("u"));
sb.Append(" [Universable sortable date/time pattern]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("y"));
sb.Append(" [Year month pattern]");
sb.Append(crlf);
sb.Append(crlf);
}
else if (optCustomDateTime.Checked)
{
sb.Append(dtmNow.ToString("d, M"));
sb.Append(" [d, M]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("d MMMM"));
sb.Append(" [d MMMM]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("dddd MMMM yy gg"));
sb.Append(" [dddd MMMM yy gg]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("h , m: s"));
sb.Append(" [h , m: s]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("hh,mm:ss"));
sb.Append(" [hh,mm:ss]");
sb.Append(crlf);
sb.Append(dtmNow.ToString("HH-mm-ss-tt"));
sb.Append(" [HH-mm-ss-tt]");
sb.Append(crlf);
sb.Append(dtmNow.ToString(@"hh:mm, G\MT z"));
sb.Append(@" [hh:mm, G\MT z]");
sb.Append(crlf);
sb.Append(dtmNow.ToString(@"hh:mm, G\MT zzz"));
sb.Append(@" [hh:mm, G\MT zzz]");


}
txtDateTime.Text = sb.ToString();
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend