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

Please advise what this output is and how I can manipulate it to get the day,date and time?
$data = (head('http://web/web.html'))[2]; print "$data\n";

OUTPUT:
1020952472.

Will I be using something like this??
$dayz = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]]; print $dayz;

Please advise if I am close and can my output be manipulated, if so how??

Replies are listed 'Best First'.
Re: Output of Date
by davis (Vicar) on May 13, 2002 at 13:17 UTC
    That looks like a unix timestamp style date. (Which, incidentally, is the number of seconds since 00:00:00 1st Jan 1970).
    To turn it into a readable value, use something like this:
    #!/usr/bin/perl -w use strict; my $timestamp = 1020952472; print scalar localtime($timestamp);
    If you want to do something a bit more clever, then read perldoc -f localtime
    cheers.
    davis
    Is this going out live?
    No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist
Re: Output of Date
by {NULE} (Hermit) on May 13, 2002 at 14:40 UTC
    Esteemed Anonymous Monk, our most prolific and inquisitive of brethren,

    I've been advocating the use of strftime at work to prevent the continual hand rolling and re-rolling of customized time functions.

    This one prints the current local time in YYYY/MM/DD HH:MM:SS format:

    use POSIX; print strftime("%Y/%m/%d %H:%M:%S", localtime),"\n";
    If you are given the time in epoch seconds try this:
    use POSIX; print strftime("%A, %B %d, %Y", localtime($epoch)),"\n";
    which will output "Day of week, Month DD, YYYY". Check the Perl documentation for POSIX (perldoc POSIX) and if you are on UNIX you can also do a "man strftime" to get a good description of the format qualifiers.

    Good luck,
    {NULE}
    --
    http://www.nule.org

      Thanks to all for your answers!
Re: Output of Date
by hotshot (Prior) on May 13, 2002 at 13:28 UTC
    you were on the right track. The long number is the number of seconds since the EPOC (somewhere in 1970). You can manipulate it as follows:
    # from O'REILLY's book $thisDay = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]]; # will retu +rn the current day of the week # localtime is typically used as follows: ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localt +ime;
    I suggest you refer to the manual for further inforamtion (see this)

    Thanks.

    Hotshot
Re: Output of Date
by perlplexer (Hermit) on May 13, 2002 at 13:19 UTC
    "1020952472" is the number of seconds since the epoch.
    What you want to do is feed this number to localtime(). Otherwise, it will use value returned by time().
    $data = (head('http://web/web.html'))[2]; $days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[(localtime $data)[ +6]];
    --perlplexer

    Update:
    fixed a typo
Re: Output of Date
by kappa (Chaplain) on May 13, 2002 at 13:19 UTC
    Try this:
    print scalar localtime($timestamp), "\n";
Re: Output of Date
by Android 18 (Novice) on May 13, 2002 at 20:57 UTC
    You could of course go out of your way to make it more difficult than it really is and make use of the Date::Calc module. You can do all sorts of fun conversions and calculations with that. Documentation can be found at CPAN.

    Once bread becomes toast, it can never be bread again.