How to put a timestamp in a filename on Windows?

Hello everyone,

On linux I do this very common thing of putting a timestamp in the filenames that are produced by my simulations:

a=1.0
b=1.5 
using Dates
filename =string(now())*"_parameter1=$(a)_parameter2=$(b).txt"
"2021-03-29T11:02:33.672_parameter1=1.0_parameter2=1.5.txt"

No problem in Linux to save a file with such a name, but on windows, this fails since windows does not accept filenames with colons.

How do people get around that issue?
I tried to reformat the timestamp, form 2021-03-29T11:02:33.672 to 2021-03-29T11-02-33.672

But I could not find the way how to do that using Dates.
Any pointers would be very much appreciated.

Thanks,
Olivier

You can use e.g. something like

Dates.format(now(),"yyyymmdd")

of course using your own formatting wishes.
You can find the format characters here: Dates · The Julia Language

3 Likes

Thanks a lot!

Olivier

1 Like