home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / tutorial / eg / ctime.pl < prev    next >
Encoding:
Text File  |  1990-03-10  |  1.0 KB  |  33 lines

  1. ;# ctime.pl is a simple Perl emulation for the well known ctime(3C) function.
  2. ;#
  3. ;# Waldemar Kebsch, Federal Republic of Germany, November 1988
  4. ;# kebsch.pad@nixpbe.UUCP
  5. ;# My private System: 80286 with Microport System V/AT 2.2
  6. ;#
  7. ;# usage:
  8. ;#
  9. ;#     #include <importenv.pl>      # see Perl library. We need the
  10. ;#                                  # environment variable TZ.
  11. ;#     #include <ctime.pl>          # see the -P and -I option in perl.man
  12. ;#     $Date = do ctime(time);
  13.  
  14. @DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  15. @MoY = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  16.  
  17. $TZ = 'CDT' unless $TZ || ($TZ = $ENV{'TZ'});
  18.  
  19. sub ctime {
  20.     local($time) = @_;
  21.     local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
  22.     local($date);
  23.  
  24.  
  25.  
  26.     ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
  27.                               = localtime($time);
  28.     $year += ($year < 70)? 2000: 1900;
  29.     $date = sprintf("%s %s %2d %2d:%02d:%02d %s %4d\n",
  30.           $DoW[$wday], $MoY[$mon], $mday, $hour, $min, $sec, $TZ, $year);
  31.     return $date;
  32. }
  33.