MMYYYY - datestamp

Z

Zee Zop

How would I find the month and year from something with a datestamp of
1078801582? (The day does not matter)
 
G

Gunnar Hjalmarsson

Zee said:
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.
 
J

Jürgen Exner

Zee said:
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

Joe Smith

Zee said:
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
 
D

Dan van Ginhoven

$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";
 
G

Gunnar Hjalmarsson

Dan said:
$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? ;-)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top