Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by DeadPoet (Scribe)
on Jan 08, 2011 at 17:52 UTC ( [id://881250]=note: print w/replies, xml ) Need Help??


in reply to How do I incorporate a timestamp into a file name?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://881250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found