18.205.109.82 |    

Navigation

Google Advertisement

Die Funktion date() gibt das Aktuelle Datum/Zeit in einem definierten Format zurück.

date
  1. #!/usr/bin/perl
  2.  
  3. # Example: 2009-09-23 17:01:25
  4. print date( "%Y-%m-%d %H:%M:%S" );
  5.  
  6. # ************************************************************
  7. # Return the current time in the given FORMAT.
  8. #
  9. #  FORMAT controls the output.
  10. #
  11. #   %a => Sun
  12. #   %A => Sunday
  13. #   %b => Jan
  14. #   %B => January
  15. #   %d => 01 (day of month)
  16. #   %F => %Y-%m-%d
  17. #   %g => 09 (last to digit of the year)
  18. #   %H => 00..23 (hour)
  19. #   %j => 001..366 (day of year)
  20. #   %m => 01..12 (month)
  21. #   %M => 00..59 (minute)
  22. #   %S => 00..59 (second)
  23. #   %s => seconds since 1970-01-01 00:00:00 UTC
  24. #   %u => 1..7 (day of week 1=Mon)
  25. #   %w => day of week 0..6 0 is Sun
  26. #   %Y => year 2009
  27.  
  28. sub date {
  29.  
  30. my ( $format, $tzone ) = @_;
  31. $format="%s" if !$format;
  32. $tzone=0 if !$tzone;
  33.  
  34. my @day = ( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' );
  35. my @days = ( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' );
  36. my @month = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );
  37. my @months = ( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
  38.  
  39. # Get the localtime by the defined time zone.
  40. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time+($tzone*3600));
  41. my $years = 1900+$year;
  42. ( $year ) = ( $years =~ m/(\d{2})$/g );
  43. $mon = $mon+1;
  44.  
  45. # Get two digits.
  46. $sec  = sprintf( "%02d", $sec  );
  47. $min  = sprintf( "%02d", $min  );
  48. $hour = sprintf( "%02d", $hour );
  49. $mon  = sprintf( "%02d", $mon  );
  50. $mday = sprintf( "%02d", $mday );
  51.  
  52. # Convert the input format into the current time format.
  53. $format =~ s#\%a#$day[($wday-1)]#g;
  54. $format =~ s#\%A#$days[($wday-1)]#g;
  55. $format =~ s#\%b#$month[($wday-1)]#g;
  56. $format =~ s#\%B#$months[($wday-1)]#g;
  57. $format =~ s#\%d#$mday#g;
  58. $format =~ s#\%F#$years\-$mon\-$mday#g;
  59. $format =~ s#\%H#$hour#g;
  60. $format =~ s#\%j#$yday#g;
  61. $format =~ s#\%m#$mon#g;
  62. $format =~ s#\%M#$min#g;
  63. $format =~ s#\%S#$sec#g;
  64. $format =~ s#\%Y#$years#g;
  65. $format =~ s#\%g#$year#g;
  66.  
  67. # Get the unix timestamp.
  68. my $tstamp = time+($tzone*3600);
  69. $format =~ s#\%s#$tstamp#g;
  70.  
  71. return $format;
  72.  
  73. }
Parsed in 0.004 seconds at 558.77 KB/s

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

User online
There are 2 users online.

Tags Cloud

Latest snippets
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)
STDERR
(Bash::Function)
radius
(CSS)
shadow
(CSS)
rotate
(CSS)
create_function
(JavaScript::Snippets)