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?
I have come across this problem several times in which I would like to
Share
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