Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Poor Man's strftime()

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

Description: 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;

print strftime( '%Y%m%d.%H%M%S', localtime() );
Comment on Poor Man's strftime()
Download Code
Re: Poor Man's strftime()
by Juerd (Abbot) on Sep 09, 2003 at 16:12 UTC

Back to Snippets Section

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-10-25 21:36 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (149 votes), past polls