Append TimeStamp to a File Name

后端 未结 6 765
清歌不尽
清歌不尽 2020-12-07 16:57

I have come across this problem several times in which I would like to have multiple versions of the same file in the same directory. The way I have been doing it using C# i

6条回答
  •  时光取名叫无心
    2020-12-07 18:02

    I prefer to use:

    string result = "myFile_" + DateTime.Now.ToFileTime() + ".txt";
    

    What does ToFileTime() do?

    Converts the value of the current DateTime object to a Windows file time.

    public long ToFileTime()

    A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC). Windows uses a file time to record when an application creates, accesses, or writes to a file.

    Source: MSDN documentation - DateTime.ToFileTime Method

提交回复
热议问题