Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET DateTime to String

Tags:

c#

.net

Is there a easy way to convert a DateTime object to a string representation like this '2010-03-03 10:38:48'.

I'm not sure what the above format is but it is different from the patterns obtainable via ToLongTimeString() etc.

Is this a case for string builder?

like image 993
Chin Avatar asked Mar 03 '10 01:03

Chin


People also ask

What is FFF in date format?

The "fff" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.


1 Answers

Like this:

date.ToString("yyyy-MM-dd hh:mm:ss")

If you want 24 hour time, replace hh with HH.

For more information, see here.

like image 94
SLaks Avatar answered Oct 28 '22 01:10

SLaks