Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Poor Man's strftime()

by liz (Monsignor)
on Sep 09, 2003 at 14:37 UTC ( [id://290054]=CUFP: print w/replies, xml ) Need Help??

Some people need strftime() but can't use POSIX::strftime for some reason. This subroutine will handle most cases. Adapt, augment the conversion hash if you need more features.
sub strftime ($@) { my ($format,$second,$minute,$hour,$day,$month,$year) = @_; my %convert = ( Y => $year + 1900, m => sprintf( '%02d',$month + 1 ), d => sprintf( '%02d',$day ), H => sprintf( '%02d',$hour ), M => sprintf( '%02d',$minute ), S => sprintf( '%02d',$second ), ); $format =~ s#%(.)#$convert{$1}#sg; $format; } print strftime( '%Y%m%d.%H%M%S', localtime() );

Replies are listed 'Best First'.
Re: Poor Man's strftime()
by Juerd (Abbot) on Sep 09, 2003 at 16:12 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (9)
As of 2024-04-23 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found