Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Answer: How do I incorporate a timestamp into a file name?

( #93313=categorized answer: print w/ replies, xml ) Need Help??

Q&A > dates and times > How do I incorporate a timestamp into a file name? - Answer contributed by particle

i prefer
use POSIX; use constant DATETIME => strftime("%Y-%m-%d_%H-%M-%S", localtime);
this returns something like "2001-07-02_15-07-32"

i use this to name temp directories, like

my $tmpdir = $ENV{TMP} . '/' . basename $0 . '.' . DATETIME . '.' . $$
which gives me a uniquely named dir. then my named temp files are more human readable, because i don't need the date/time string in their names.

~Particle

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2016-07-30 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (264 votes). Check out past polls.