Solved

C# Format Date Time

Posted on 2013-01-14
3
693 Views
Last Modified: 2013-01-19
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)
0
Comment
Question by:CipherIS
  • 2
3 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 38775051
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)
0
 
LVL 1

Accepted Solution

by:
CipherIS earned 0 total points
ID: 38775063
Figured it out

DateTime.Now.ToString("yyyyMMddHHmm")
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 38796076
Figured it out
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question