Reputation: 13290
I need to break up date time, currently when I use:
Write(DateTime.Now);
it displays: 5/17/2011 03:30:00 PM
What I need it to look like is: 5/17/2011, 03:30:00 PM
I basically need a comma between the date & time.
My thinking was to parse them and write them separately, but I have been unsuccessful in my attempts.
Any thoughts or suggestions on how to do this.
Upvotes: 0
Views: 171
Reputation: 4634
Try looking at the ToShortDateString
and ToShortTimeString
methods. You should be able to accomplish what you need in a variety of ways.
Write(string.Format("{0}, {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()));
Upvotes: 1
Reputation: 4129
DateTime dateTime = DateTime.Now;
Write(string.Format("{0}, {1}", dateTime.ToShortDateString(), dateTime.ToLongTimeString()));
Upvotes: 0
Reputation: 69983
You can use the .ToString()
method which takes in a format.
DateTime.Now.ToString("MM/dd/yyyy, hh:mm:ss tt");
Here is a nice little reference guide to string formatting
Upvotes: 4