Nice Clean Example

Sample date is Jan 2, 2007 at 1:03:04.025 PM
Select the way you want the field to display to see its format specifier
Weekday      
Month  
Day    
Year    
Hour      
Minute    
Second    
Fraction      
Fraction    
TimeZone    
AM/PM    
// Examples of this formatting for this sample date
DateTime dt = new DateTime(2007, 1, 2, 13, 3, 4, 25);
String.Format("{0:}",dt);
dt.ToString("");
// Result of format is ""
The characters / and : can be used as separators
dt.ToString("MM/dd/yy HH:mm:ss") = "01/02/07 13:03:04"
// Any character can be added with a \c. In C# have to double it
dt.ToString("dddd\\, MMM %d") = "Tuesday, Jan 2"

1 responses