DateTime.ToString(“MM/dd/yyyy HH:mm:ss.fff”) resulted in something like “09/14/2013 07.20.31.371”

后端 未结 6 1970
旧巷少年郎
旧巷少年郎 2020-12-22 20:08

I have a WP8 app, which will send the current time to a web service.

I get the datetime string by calling

DateTime.ToString(\"MM/dd/yyyy HH:mm:ss.ff         


        
6条回答
  •  清歌不尽
    2020-12-22 20:51

    : has special meaning: it is The time separator. (Custom Date and Time Format Strings).

    Use \ to escape it:

    DateTime.ToString(@"MM/dd/yyyy HH\:mm\:ss.fff")
    

    Or use CultureInfo.InvariantCulture:

    DateTime.ToString("MM/dd/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture)
    

    I would suggest going with the second one, because / has special meaning as well (it is The date separator.), so you can have problems with that too.

提交回复
热议问题