Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

create array from strftime

by mhearse (Chaplain)
on Jun 20, 2012 at 17:37 UTC ( #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 (Pope) 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
Node Status?
node history
Node Type: perlquestion [id://977425]
Approved by ikegami
help
Chatterbox?
[Corion]: . o O ( I seem to have improved my skills of getting other people to write code for me )
[ambrus]: ambrus's scratchpad
[ambrus]: Also, I was wrong, apparently you have to support both periodic and one-shot timers in an AnyEvent backend
[Corion]: ambrus: That looks deceptively simple, but maybe that's simply all that's needed. Which would be great! I hope I get to test it tomorrow, thanks!!

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2016-12-08 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (141 votes). Check out past polls.