Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

C# Format Date Time

This is prob an easy question but I am having issue.  I need to print date time in the following format.

Input -> Date Jan 14, 2013 Time 1:02 pm

Output -> 20130114 1302

I used below but it just prints

yyyyMMddHHmm

string.Format("yyyy", DateTime.Now.Year) +
string.Format("MM", DateTime.Now.Month) +
string.Format("dd", DateTime.Now.Day)

string.Format("HH", DateTime.Now.TimeOfDay.Hours) + string.Format("mm", DateTime.Now.TimeOfDay.Minutes)
Avatar of dustock
dustock
Flag of United States of America image

instead of using yyyy,MM, etc replace with {0} to hold the value.

You could do this:
string.Format("Date {0} {1}, {2} Time {3}:{4}", DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year, DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes)
ASKER CERTIFIED SOLUTION
Avatar of CipherIS
CipherIS
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CipherIS

ASKER

Figured it out