|
|
Convert date string of unix time (2005-06-16 10:00:00 => 1118916000), observed the time shift and summer/winter time.
|
|
|
date2time
#!/usr/bin/perl # required perl package... use POSIX qw(strftime); print date2time( '2007-08-17 10:45:22' ); # ************************************************************ # convert date string ot unix time (2005-06-16 10:00:00 => 1118916000), # observed the time shift and summer/winter time. sub date2time { my ( $datestr, $tzone ) = @_; $tzone=0 if !$tzone; # $date[8] => (1=stime/0=wtime)... my @date=localtime(time); my ($date, $time)=split(/ /, $datestr); my ($year, $mon, $day) = split(/\-/, $date); my ($hour, $min, $sec) = split(/\:/, $time); $year = $year-1900; $mon = $mon-1; if ($date[8]) { $hour=( $hour+($tzone+1) ) } else { $hour=( $hour+$tzone ) } my $unixtime = POSIX::strftime( "%s", $sec, $min, $hour, $day, $mon, $year ); return $unixtime; }
|
|
|
|