by
Roland Schumacher alias GENiALi
23. September 2009 -- 138
words -- 1 mal gelesen
You never learn from. It should be.
I have the task to create a log file again. This should give the file a meaningful name. About "20090923_080355.txt". Such file names can now be built with the wildest methods.
Here an example from my early days (OK.) (This is not so long ago).
DateTime now = DateTime.Now;
string fileName = now.Year.ToString("0000") + now.Month.ToString("00") + now.Day.ToString("00") + "_" + now.Hour.ToString("00") + now.Second.ToString("00") + now.Millisecond.ToString("000") + ".txt";
Looks but quite workable. In any case, it works. But it is also easier?
It is a lot easier.
DateTime now = DateTime.Now;
string fileName = jetzt.ToString("yyyyMMdd_HHmmss_FFF") + ".txt";
Looks but already much more elegant.
To the info. "FFF" stands for the milliseconds. MSDN is to discover a lot more.
This gives but beautiful log file name. Can log file name be beautiful? ;-)
70ba79c5-6a1b-4166-bfac-f7d6c2ae9e00|0|.0
Tags: