DateTime timeUtcWhenCommentPostingOccurred = getDateAndTimeOfCommentPostingInUtc();
DateTime estTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtcWhenCommentPostingOccurred, estZone);
estTime.ToString("YYYY-MM-DD HH':'MM':'SS");
The above specified format shows the following Incorrect date format :
YYYY-11-DD 21:11:SS
Why does the year, day and second fail to show up properly? Please provide suggestions as to how I can fix the issue above.
y
for Year, not upper case Y
.d
not upper case D
m
not upper case M
, upper case M
is
for month,s
, not upper case S
See:Custom Date and Time Format Strings
So your format should be:
estTime.ToString("yyyy-MM-dd HH:mm:ss");
Format strings are care-sensitive. YYYY
, DD
, and SS
are not recognized format strings for DateTime
, so they are treated as literal characters.
Use
estTime.ToString("yyyy-MM-dd HH:mm:ss");
instead.
Note the distinction between MM
(month) and mm
(minute).
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