Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

create array from strftime

by mhearse (Chaplain)
on Jun 20, 2012 at 17:37 UTC ( [id://977425]=perlquestion: print w/replies, xml ) Need Help??

mhearse has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to do:
my ($day, $month, $year) = strftime "%d %m %Y", time();
Because that doesn't populate the array.

Replies are listed 'Best First'.
Re: create array from strftime
by ikegami (Patriarch) on Jun 20, 2012 at 17:45 UTC

    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.

      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?
Re: create array from strftime
by Anonymous Monk on Jun 20, 2012 at 17:44 UTC

    <serious joker>Sure, all you do is stuff some dynamite into your pants and light the fuze

    the opposite of strftime is strptime, DateTime comes with both

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found