I am trying to display date time as follows Wednesday, 05 May 2014 21:25
I tried the following but when using ToLongDateString
I am not getting time, this is my code
DateTime date = DateTime.Now;
string formattedDate = date.ToLongDateString();
string fDate = date.ToString("MMMM dd, yyyy,H:mm");
Response.Write(formattedDate);
The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.
Two 'H' in HH is for 24-hour format. Description as to why this works would be useful. Such as HH for 24 hour format as hh for 12 hour.
4-digit year, month, day, 24-based hour, minute, second -- usually with leading zeroes. These six are the easiest formats to use and remember in Time::Format: yyyy , mm , dd , hh , mm , ss .
To get the current time in particular, you can use the strftime() method and pass into it the string ”%H:%M:%S” representing hours, minutes, and seconds.
Date string does not include time. That's why it called date string. Here is your desired format:
DateTime date = DateTime.Now;
string formattedDate = date.ToString("dddd, dd MMMM yyyy HH:mm");
// Wednesday, 07 May 2014 12:05
ToLongDateString
does not contain the time, as the time is not part of the date.
See HERE for some details:
Current culture: "en-US"
Long date pattern: "dddd, MMMM dd, yyyy" Long date string: "Wednesday, May 16, 2001"
Long time pattern: "h:mm:ss tt" Long time string: "3:02:15 AM"
Short date pattern: "M/d/yyyy" Short date string: "5/16/2001"
Short time pattern: "h:mm tt" Short time string: "3:02 AM"
Also HERE and HERE on all the possiblities with ToString
for DateTime
.
You possibly want to use ToString("F")
:
The "F" standard format specifier represents a custom date and time format string that is defined by the current DateTimeFormatInfo.FullDateTimePattern property. For example, the custom format string for the invariant culture is "dddd, dd MMMM yyyy HH:mm:ss".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With