Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

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

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

For a standard implementation that may be reused throughout the program:

Example

use Time::localtime; sub timestamp { my $t = localtime; return sprintf( "%04d-%02d-%02d_%02d-%02d-%02d", $t->year + 1900, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec ); } print '[' . timestamp() . ']: my message'. "\n";

Output:

[2011-01-08_11-48-29]: my message

Comment on Answer: How do I incorporate a timestamp into a file name?
Select or Download Code
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 meditating upon the Monastery: (15)
As of 2015-07-31 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls