自定义日期时间格式

自定义日期时间格式

问题描述:

我需要格式化日期,如2010-04-21 11:35:22.440。 ?谁能帮助我

i need to format date like "2010-04-21 11:35:22.440". can anyone help me?

问题是我看到无论是2009-06-15T13:45:30.0900000或2008-03-09 16:05:07Z但不一个我期待的。谢谢

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.

使用格式YYYY-MM-DD HH:MM:SS.FFF 的日期变量的ToString

Use the format "yyyy-MM-dd hh:mm:ss.fff" with the ToString of the date variable.

例如:

Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));