Datetime.Now without special characters?

I'm using C# .NET 2.0.  Is there a method that will strip out slashes and colons from DateTime.Now so that 7/29/07 12:50:20 PM looks like:
072907_125020PM

where I'm adding the underscore?
brettrAsked:
Who is Participating?
 
Ted BouskillConnect With a Mentor Senior Software DeveloperCommented:
You can format the string any way you want.

DateTime.Now.ToString("MMddyy_hhmmsstt");
0
 
DarkoLordConnect With a Mentor Commented:
DateTime.Now.ToString("MMddyyyy_hhmmtt")

However note that the time will be displayed in 12 hour fourmat, however AM/PM designator will be added only where it is defined in the regional settings
0
 
DhaestConnect With a Mentor Commented:
Did you look at the format-function ?
http://blog.stevex.net/index.php/string-formatting-in-csharp/

MyDate = String.Format({0:ddMMyyyy_t,DateTime.Now())
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.