Dot Net Date Formatting

Hi, all of you people may have encountered situation where you wish to format your date for a specific format. This becomes very simple with Dot NET Framework.

Suppose you have a date to be displayed. Let the date be 1st January 2009
Now, this can be displayed in various formats. The respective date-format-string is displayed alongside Eg:

Displaying these can be done using the following LOC.

DateTime today=DateTime.Now;
string formattedDate=today.ToString();

Eg:
string formattedDate=today.ToString("dd-MM-yyyy");
=>01-Jan-2009

string formattedDate=today.ToString("dd/MM/yyyy");
=>01-Jan/2009

string formattedDate=today.ToString("d-MMM-yy");
=>1-January-2009

Try out other combinations of your own and experience the power!!!!!!!


















FormatRespective date-format-string
01/01/09'dd/MM/yy'
01 Jan 09'dd MM yy'
01 Jan 2009'dd MM yyyy'
1 January 2009'd MMM yyyy'

Comments

Popular posts from this blog

Encrypt and Decrypt Images Using Java

Build your own Network sniffer

ASP Response.Write newline