Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date to String with pattern problem

Tags:

c#

.net

Is there a way to convert DateTime object by some pattern to string of following pattern.

"yyyy-MM-dd HH:mm:ss.fff"


    /// yyyy - the year as in 2005
    /// yy   - the year as in 05, leading zero if necessary
    /// MM   - the month with two digits, leading zero if necessary
    /// dd   - the day of the month with two digits, leading zero if ncessary
    /// HH   - the hour of the day in 24 hours format, leading zero if necessary
    /// mm   - the minute of the hour with two digits, leading zero if necessary
    /// ss   - the second of the minute with two digits, leading zero if necessary
    /// fff  - the fraction of the second with three digits, leading zero if necessary

Thanks a lot for help.

like image 319
Night Walker Avatar asked Jun 03 '26 20:06

Night Walker


1 Answers

Yes, this van be done with

String.Format("{0:yyyy-MM-dd HH:mm:ss:fff}", yourdatetime);
like image 186
Bas Danen Avatar answered Jun 06 '26 09:06

Bas Danen