Monday, May 21, 2007

Date Time Formatting with C#

Here is the simplest way of formatting DateTime in to string,

string sDateTime = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");

you can change last part into any format you like...

Ex.
dd-MM-yyyy
dd-MM-yyyy HH:mm
dd-MM-yy HH:mm:ss
dd-MM-yyyy HH:mm:ss

No comments: