18.117.182.179 |    

Navigation

Google Advertisement

Convert date string of unix time (2005-06-16 10:00:00 => 1118916000), observed the time shift and summer/winter time.

date2time
  1. #!/usr/bin/perl
  2.  
  3. # required perl package...
  4. use POSIX qw(strftime);
  5.  
  6. print date2time( '2007-08-17 10:45:22' );
  7.  
  8. # ************************************************************
  9. # convert date string ot unix time (2005-06-16 10:00:00 => 1118916000),
  10. # observed the time shift and summer/winter time.
  11.  
  12. sub date2time {
  13.  
  14. my ( $datestr, $tzone ) = @_;
  15. $tzone=0 if !$tzone;
  16.  
  17. # $date[8] => (1=stime/0=wtime)...
  18. my @date=localtime(time);
  19.  
  20. my ($date, $time)=split(/ /, $datestr);
  21. my ($year, $mon, $day) = split(/\-/, $date);
  22. my ($hour, $min, $sec) = split(/\:/, $time);
  23. $year = $year-1900;
  24. $mon = $mon-1;
  25.  
  26. if ($date[8]) { $hour=( $hour+($tzone+1) ) } else { $hour=( $hour+$tzone ) }
  27. my $unixtime = POSIX::strftime( "%s", $sec, $min, $hour, $day, $mon, $year );
  28.  
  29. return $unixtime;
  30.  
  31. }
Parsed in 0.002 seconds at 498.84 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 3 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)