Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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: (6)
As of 2016-06-30 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (400 votes). Check out past polls.