i need to format date like "2010-04-21 11:35:22.440".开发者_开发技巧 can anyone help me?
the problem is i am seeing either 2009-06-15T13:45:30.0900000 or 2008-03-09 16:05:07Z but not the one i am looking for. thanks.
string formattedDate = dateTime.ToString("yyyy-MM-dd HH\\:mm\\:ss.fff");
Note that the case of MM and HH are important, MM is months, mm is minutes, and HH is 24h, vs hh being 12h.
Also notice the time separator is specified as \:, if you just use : it will use the time separator specified in your regional settings, which may not necessarily be a colon.
Custom Date and Time Format Strings link should point you in the right direction.
Use the format "yyyy-MM-dd hh:mm:ss.fff"
with the ToString of the date variable.
e.g:
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
精彩评论