?
Solved

C# Format Date Time

Posted on 2013-01-14
3
Medium Priority
?
730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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