Why the time has come 0000 when I use today's date in C #

I am trying to create a string to display the current date and time, not wanting to use any slashes just numbers.

For example, 09 jun 2011 11AMshould be201109061100

But when I run the code below, time is always 0000

Conclusion:

ResultLog201109060000

the code:

DateTime currDate = DateTime.Today;
String resultlogFilename;
resultlogFilename = 
    "ResultLog" + 
    currDate.ToString("yyyy") + 
    currDate.ToString("dd") + 
    currDate.ToString("MM") + 
    currDate.ToString("HH") + 
    currDate.ToString("mm");

Any idea how to choose the right time?

+3
source share
4 answers

DateTime.Today seems to return the Date part not the hour part.

Just use DateTime.Now to get the full time.

http://msdn.microsoft.com/en-us/library/system.datetime.now.aspx

Msdn DateTime.Today

, Today , . . DateTime, DateTimeOffset TimeZoneInfo. , TimeOfDay , Now , .

+5
var resultlogFilename = string.Format("ResultLog{0:yyyyddMMhhmm}", DateTime.Now);
+3

DateTime.Now .Today. "" "" , (0:00).

+2

, :)

0

All Articles