18.219.130.41 |    

Navigation

Google Advertisement

Wandelt Datum-String in Unixzeit um (2005-06-16 10:00:00 => 1118916000), beachtet dabei Zeitverschiebung und Sommer/Winterzeit.

date2time
  1. #!/bin/bash
  2.  
  3. # ************************************************************
  4. # Wandelt Datum-String in Unixzeit um (2005-06-16 10:00:00 => 1118916000),
  5. # beachtet dabei Zeitverschiebung und Sommer/Winterzeit.
  6.  
  7. function date2time() {
  8.  
  9. local date=$1
  10. local zone=$2
  11. echo $date | perl -e '
  12.  
  13. # benoetigtes Perl Modul...
  14. use POSIX qw(strftime);
  15.  
  16. my $datestr="'$date'";
  17. my $tzone='$zone';
  18.  
  19. # $date[8] => (1=stime/0=wtime)...
  20. my @date=localtime(time);
  21.  
  22. my ($date, $time)=split(/ /, $datestr);
  23. my ($year, $mon, $day) = split(/\-/, $date);
  24. my ($hour, $min, $sec) = split(/\:/, $time);
  25. if ($date[8]) { $hour=( $hour+($tzone+1) ) } else { $hour=( $hour+$tzone ) }
  26. $mon = $mon-1;
  27. $year = $year-1900;
  28. my $unixtime = POSIX::strftime( "%s", $sec, $min, $hour, $day, $mon, $year );
  29. print $unixtime;
  30.  
  31. '
  32.  
  33. }
  34.  
  35. # ************************************************************
  36.  
  37. # Datum von Gestern...
  38. YESTERDAY=$( date -d yesterday +%Y-%m-%d )
  39.  
  40. # Stunde...
  41. STD="10"
  42.  
  43. # Uebergabeparameter: Datumstring, Zeitverschiebung...
  44. date2time "$YESTERDAY $STD:00:00" "+1"
Parsed in 0.002 seconds at 512.83 KB/s

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

User online
There are 1 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)