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

前端 未结 8 2099
北恋
北恋 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:34

    You can make a path for your file as bellow:

    string path = "fileName-"+DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss") + ".txt";
    

提交回复
热议问题