custom date time format

后端 未结 3 409
情话喂你
情话喂你 2021-01-21 10:24

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

3条回答
  •  野的像风
    2021-01-21 11:11

    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.

提交回复
热议问题