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

Re: create array from strftime

by ikegami (Pope)
on Jun 20, 2012 at 17:45 UTC ( #977431=note: print w/ replies, xml ) Need Help??


in reply to create array from strftime

Problem #1: strftime doesn't take an epoch time for argument.

Problem #2: strftime returns a single string.

Then there's also the fact that "3 scalars" are not "an array".

Solution:

my ($day, $month, $year) = (localtime)[3,4,5]; $month += 1; $year += 1900;

localtime.


Comment on Re: create array from strftime
Select or Download Code
Re^2: create array from strftime
by taint (Chaplain) on Jun 20, 2012 at 18:07 UTC
    Or read the output of strftime(3). :)
    Here's another example:
    use POSIX qw(strftime); # POSIX is your friend # see man strftime(3) for format options my $gmtstring = strftime "%F %H:%I:%S %z", localtime; print $gmtstring;

    Hope this helps.


    my $perl_version( 5.12.4 );
    print $perl_version;
      How does one use that to populate $day, $month and $year?
        I used this to populate Month. Couldn't something similar be used for Year & Day?
        use Time::Piece; use strict; my @months = qw( 01 02 03 04 05 06 07 08 09 10 11 12 ); my $t = localtime; print localtime->month(@months);
        my $perl_version( 5.12.4 );
        print $perl_version;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://977431]
help
Chatterbox?
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-12-28 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (180 votes), past polls