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# is by adding a time stamp to the file name with something like this DateTime.Now.ToString().Replace('/', '-').Replace(':', '.')
.
Is there a better way to do this?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
you can use:
I prefer to use:
What does ToFileTime() do?
Source: MSDN documentation - DateTime.ToFileTime Method
You can use below instead:
You can use DateTime.ToString Method (String)
DateTime.Now.ToString("yyyyMMddHHmmssfff")
or string.Format
string.Format("{0:yyyy-MM-dd_hh-mm-ss-fff}",DateTime.Now)
;or Interpolated Strings
$"{DateTime.Now:yyyy-MM-dd_hh-mm-ss-fff}"
With Extension Method
Usage:
Extension method
Perhaps appending
DateTime.Now.Ticks
instead, is a tiny bit faster since you won't be creating 3 strings and the ticks value will always be unique also.