($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)= stat($name);
Where $name is the full path to the file I want info on.
$atime= last access
$mtime= last modified
$ctime= create time, (not always correct, depends on how file was last opened)
($sec,$min,$hour,$mday,$mon,$myear) = localtime($mtime);
$myear is years since 1900, ( add 1900 to get the 4 digit year)
$mon is the numeric month with ZERO for JANUARY so add one to use it
In practice, here is the code I use (I come here to copy it as needed):
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
= stat($name);
@months =('01','02','03','04','05','06','07','08','09','10','11','12');
@days=('00','01','02','03','04','05','06','07','08','09','10',
'11','12','13','14','15','16','17','18','19','20',
'21','22','23','24','25','26','27','28','29','30',
'31','32','33','34','35','36','37','38','39','40',
'41','42','43','44','45','46','47','48','49','50',
'51','52','53','54','55','56','57','58','59','60');
($sec, $min, $hour,$mday, $mon, $year, $wday, $yday, $isdst) =localtime($mtime);
$year=$year+1900;
$typical_date ="$months[$mon]/$days[$mday]/$year";
$sql_timestamp=$year.$months[$mon].$days[$mday].$days[$hour].$days[$min].$days[$sec];
the months array prefixes a zero, and adds one.
The days array is used to add the leading zero where needed. I use this array to do the same thing for hours, minutes and seconds (hence the reason why I list days up 2 60. That could also be done using sprintf("%02d", $number); But for this simple case, This looks cleaner to me.
A small amount of time could be saved moving the arrays definitions to some global location. In practice, this is never the most seriuos bottleneck.
Ctime format:
use Time::localtime;
$mod_time=ctime($mtime); ## gives us a string format
print"$mod_time ( ctime format)\n";
## prints "Mon Apr 25 11:58:41 2005"
Is there a way to change this format ??
|