分类: Python/Ruby
2011-12-22 15:05:08
1.
#!/usr/bin/perl -w
my $local_time=&GetTimestamp;
print "Local Time: $local_time\n";
sub GetTimestamp
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year=$year+1900;
return $year . sprintf('%02u%02u_%02u%02u%02u', $mon+1, $mday, $hour, $min, $sec);
}
perl sprintdate.pl
Local Time: 20111222_150720
2.
#!/usr/bin/perl -w
use strict;
#my $date=localtime;
#print "$date\n";
sub GetDateToday
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year=$year+1900;
return $year.'-'.sprintf('%02u-%02u', $mon+1, $mday);
}
my $cur_date=GetDateToday();
print "$cur_date\n";
print "$^O\n";
perl date.pl
2011-12-22
linux
$^O 表示当前系统