Solved

C# Format Date Time

Posted on 2013-01-14
3
682 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
Comment Utility
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
Comment Utility
Figured it out

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

Author Closing Comment

by:CipherIS
Comment Utility
Figured it out
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now