DateTime.ToString() format that can be used in a filename or extension?

前端 未结 8 2101
北恋
北恋 2020-12-12 16:53

I want to add a timestamp to filenames as files are created but most of the DateTime methods I\'ve tried output something with spaces and slashes. For instance:



        
相关标签:
8条回答
  • 2020-12-12 17:39

    Personally I like it this way:

    DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss")
    

    Because it distinguishes between the date and the time.

    0 讨论(0)
  • 2020-12-12 17:42

    I would use the ISO 8601 format, without separators:

    DateTime.Now.ToString("yyyyMMddTHHmmss")
    
    0 讨论(0)
提交回复
热议问题