/ Published in: Perl
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
sub convertTime { #expects time in yyyy-mm-dd hh:mm:ss format my $oneday = 24 * 3600; #for convenience my $utime = $sec + ($minute * 60) + ($hour * 3600); ## time in seconds on the day in question $year -= 1970; my @months = (31,28,31,30,31,30,31,31,30,31,30,31); for (my $i=0; $i < ($month-1); $i++ ) { $utime += ($months[$i] * $oneday); } $utime += ((($year - ($year%4))/4) * $oneday); ## take leap years into account if( ($year%4)==0 && $month < 3 ) { $utime -= $oneday; } $utime += (($day-1) * $oneday); $utime += ($year * 365 * $oneday); }