This is a somewhat subjective question, and not very important in the big scheme of things, but something that yet annoys me regularly. There seems to be no self-evident way to put a timestamp in a file name.
Objective issue is that timestamps in file names should be sortable. But .NET sortable date formats like "s" ("yyyy-MM-ddTHH:mm:ss"
) and "u" ("yyyy-MM-dd HH:mm:ssZ"
) are not valid in file names because of ':' characters.
Other thing is that you should easily see if universal or local time is used. Practically, users seem to prefer local time to universal time.
I have mostly ended up using ISO 8601 with basic time format:
"yyyy-MM-ddTHHmmsszz"
"yyyy-MM-ddTHHmmssZ"
In these formats my current local time would be "2009-08-08T151800+03"
and UTC "2009-08-08T121800Z"
You can also autodetect the DateTime.Kind with "K" and use "yyyy-MM-ddTHHmmssK"
, but then you'll have to replace the ':' characters.
Any other suggestions?
Edit: A few notes so far:
local time + time zone format "yyyy-MM-ddTHHmmsszz"
is no longer sortable if multiple time zones are involved. In most cases it would make sense to drop the time zone info if it is redundant, and use UTC otherwise.
Another thing is that UTC should always be marked with 'Z', 'GMT' or 'UTC' to prevent guesswork and mistakes.
Julian dates and other stardates are cool because date arithmetic with the gregorian calendar is braindead.
If the date is included, write this in numbers: YYYY-MM-DD. For example, use “2017-01-10” rather than “January_10th”. If numbering files, consider how many potential files are needed and use the appropriate number of leading zeros: 001, 002, etc., will order files up to 999.
When creating file names with dates, I like to use the YYYY-MM-DD format, making sure to use two digits for both month and day, even if you would typically use only one digit when writing it out.
The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD.
I use this:
My-File--2009-12-31--23-59-59.txt
--UTC
" after the time.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With