MMYYYY - datestamp

Discussion in 'Perl' started by Zee Zop, Sep 20, 2004.

  1. Zee Zop

    Zee Zop Guest

    How would I find the month and year from something with a datestamp of
    1078801582? (The day does not matter)
     
    Zee Zop, Sep 20, 2004
    #1
    1. Advertising

  2. Zee Zop wrote:
    > How would I find the month and year from something with a datestamp
    > of 1078801582? (The day does not matter)


    perldoc -f localtime
    perldoc -f gmtime

    Next time, post to comp.lang.perl.misc instead. This group is defunct.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Sep 20, 2004
    #2
    1. Advertising

  3. Zee Zop wrote:
    > How would I find the month and year from something with a datestamp of
    > 1078801582? (The day does not matter)


    Is this from the Romulan or the Klingon calendar?

    jue
     
    Jürgen Exner, Sep 20, 2004
    #3
  4. Zee Zop

    Joe Smith Guest

    Zee Zop wrote:

    > How would I find the month and year from something with a datestamp of
    > 1078801582?


    You want localtime() in list context. Be mindfull of $month+1 and $year+1900.

    Using localtime() in scalar context is also handy:
    perl -le 'print scalar localtime 1078801582'

    -Joe
     
    Joe Smith, Sep 21, 2004
    #4
  5. $MYTIMESTAMP = "1095967319";

    ($ss,$mi,$hh,$dd,$mm,$yy ,$wday,$ddd ,$isdst) = localtime($MYTIMESTAMP);
    $yy+=1900;
    $mm+=1;
    $mm = substr("0".$mm,-2,2);
    $dd = substr("0".$dd,-2,2);
    $hh = substr("0".$hh,-2,2);
    $mi = substr("0".$mi,-2,2);
    $ss = substr("0".$ss,-2,2);
    print "$yy-$mm-$dd $hh:$mi:$ss";


    "Zee Zop" <> wrote in message
    news:x1E3d.8097$...
    > How would I find the month and year from something with a datestamp of
    > 1078801582? (The day does not matter)
    >
    >
     
    Dan van Ginhoven, Oct 1, 2004
    #5
  6. Dan van Ginhoven wrote:
    > $MYTIMESTAMP = "1095967319";
    >
    > ($ss,$mi,$hh,$dd,$mm,$yy ,$wday,$ddd ,$isdst) = localtime($MYTIMESTAMP);
    > $yy+=1900;
    > $mm+=1;
    > $mm = substr("0".$mm,-2,2);
    > $dd = substr("0".$dd,-2,2);
    > $hh = substr("0".$hh,-2,2);
    > $mi = substr("0".$mi,-2,2);
    > $ss = substr("0".$ss,-2,2);
    > print "$yy-$mm-$dd $hh:$mi:$ss";


    What kind of grudge do you have against the sprintf() function? ;-)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 1, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil M

    display datestamp in HTML

    Phil M, Mar 2, 2007, in forum: Perl Misc
    Replies:
    9
    Views:
    271
    Joe Smith
    May 18, 2007
  2. Phil M

    Display datestamp script in HTML

    Phil M, Mar 2, 2007, in forum: Javascript
    Replies:
    17
    Views:
    303
    nice.guy.nige
    Mar 4, 2007
Loading...

Share This Page