2008年6月15日 星期日

又係日期時間

真係無乜辦法, 無論用邊隻語言, 都係要砌時間.

localtime.pl

#!/usr/bin/perl
my @now = localtime();

for($i=0;$i <= $#now; $i++)
{
print "$now[$i]\n";
}


timelocal.pl

#!/usr/bin/perl
use Time::Local;

my $offset = shift; $offset = 0 if (!($offset));

my $time = time();
my $ltime = localtime($time);
my ($t0,$t1,$t2,$t3,$t4,$t5) = (localtime($time))[0,1,2,3,4,5];
my $tlime = timelocal($t0,$t1,$t2,$t3,$t4,$t5+1900);

print "$t0,$t1,$t2,$t3,$t4,$t5\n";
print "timestamp = $time\nlocaltime = $ltime\ntimelocal = $tlime\n";

my ($o0,$o1,$o2,$o3,$o4,$o5) = (localtime($time - (86400 * $offset)))[0,1,2,3,4,5];
my $daystart = timelocal(0,0,0,$o3,$o4,$o5+1900);
my $dayend = timelocal(59,59,23,$o3,$o4,$o5+1900);
print "oldday : start = $daystart, end = $dayend\n";

沒有留言: