home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / question / 13822 < prev    next >
Encoding:
Text File  |  1992-11-22  |  2.7 KB  |  82 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!mcsun!sunic!sics.se!eua.ericsson.se!ericom!eos.ericsson.se!etxmesa
  3. From: etxmesa@eos.ericsson.se (Michael Salmon)
  4. Subject: Re: Tomorrow's date? (Utility?)
  5. Message-ID: <1992Nov23.091446.1193@ericsson.se>
  6. Keywords: date utility
  7. Sender: news@ericsson.se
  8. Nntp-Posting-Host: eos6c02.ericsson.se
  9. Reply-To: etxmesa@eos.ericsson.se (Michael Salmon)
  10. Organization: Ericsson Telecom AB
  11. References:  <1992Nov16.231545.10656@cheshire.oxy.edu>
  12. Distribution: comp.unix.shell
  13. Date: Mon, 23 Nov 1992 09:14:46 GMT
  14. Lines: 66
  15.  
  16. In article <1992Nov16.231545.10656@cheshire.oxy.edu>, legend@cheshire.oxy.edu (Linda A. Malcor) writes:
  17. |> I'm looking for a (standard) unix utility that can tell me what tommorow's
  18. |> date is (as well as the date 15hrs in the future/past, etc.). Any ideas?
  19. |> Date math is so common, I'd just like to avoid reinventing the wheel.
  20.  
  21. perl isn't yet a standard utility but it is available for most if not
  22. all Unix system as well as some others.
  23.  
  24.      localtime EXPR
  25.              Converts a time as returned by the time function  to
  26.              a  9-element  array  with  the time analyzed for the
  27.              local timezone.  Typically used as follows:
  28.  
  29.              ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  30.                                            localtime(time);
  31.  
  32.              All array elements are numeric,  and  come  straight
  33.              out  of  a struct tm.  In particular this means that
  34.              $mon has the range 0..11 and  $wday  has  the  range
  35.              0..6.  If EXPR is omitted, does localtime(time).
  36.  
  37. Here is an example of how you can get a simple printout of the time in
  38. 24 hours:
  39.  
  40.  eos6c02 tmp 83 > cat tomorrowtest 
  41. #!/usr/gnu/bin/perl
  42. #
  43. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  44.     localtime(time + 86400);
  45. printf "%02d%02d%02d %02d:%02d:%02d\n",
  46. $year+1900,
  47. $mon + 1,
  48. $mday,
  49. $hour,
  50. $min,
  51. $sec;
  52.  eos6c02 tmp 84 > date
  53. Mon Nov 23 10:06:08 MET 1992
  54.  eos6c02 tmp 85 > ./tomorrowtest 
  55. 19921124 10:06:11
  56.  
  57. More date like output is possible using string arrays. Date arrithmetic
  58. is also possible just by changing the value added to time above, 86400
  59. is the number of seconds in 1 day. Rather than a constant you could use
  60. an expression, you could even read the expression from the command line
  61. or input.
  62.  
  63. N.B. the setting of TZ is a not a portable way to affect date:
  64.  
  65.  eos6c02 tmp 90 > date
  66. Mon Nov 23 10:12:11 MET 1992
  67.  eos6c02 tmp 91 > ( setenv TZ MET-1MET ; date )
  68. Mon Nov 23 10:12:20 MET 1992
  69.  eos6c02 tmp 92 > ( setenv TZ MET-25MET ; date )
  70. Mon Nov 23 09:12:25 MET 1992
  71.  
  72. -- 
  73.  
  74. Michael Salmon
  75.  
  76. #include    <standard.disclaimer>
  77. #include    <witty.saying>
  78. #include    <fancy.pseudo.graphics>
  79.  
  80. Ericsson Telecom AB
  81. Stockholm
  82.