home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!mcsun!sunic!sics.se!eua.ericsson.se!ericom!eos.ericsson.se!etxmesa
- From: etxmesa@eos.ericsson.se (Michael Salmon)
- Subject: Re: Tomorrow's date? (Utility?)
- Message-ID: <1992Nov23.091446.1193@ericsson.se>
- Keywords: date utility
- Sender: news@ericsson.se
- Nntp-Posting-Host: eos6c02.ericsson.se
- Reply-To: etxmesa@eos.ericsson.se (Michael Salmon)
- Organization: Ericsson Telecom AB
- References: <1992Nov16.231545.10656@cheshire.oxy.edu>
- Distribution: comp.unix.shell
- Date: Mon, 23 Nov 1992 09:14:46 GMT
- Lines: 66
-
- In article <1992Nov16.231545.10656@cheshire.oxy.edu>, legend@cheshire.oxy.edu (Linda A. Malcor) writes:
- |> I'm looking for a (standard) unix utility that can tell me what tommorow's
- |> date is (as well as the date 15hrs in the future/past, etc.). Any ideas?
- |> Date math is so common, I'd just like to avoid reinventing the wheel.
-
- perl isn't yet a standard utility but it is available for most if not
- all Unix system as well as some others.
-
- localtime EXPR
- Converts a time as returned by the time function to
- a 9-element array with the time analyzed for the
- local timezone. Typically used as follows:
-
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
- localtime(time);
-
- All array elements are numeric, and come straight
- out of a struct tm. In particular this means that
- $mon has the range 0..11 and $wday has the range
- 0..6. If EXPR is omitted, does localtime(time).
-
- Here is an example of how you can get a simple printout of the time in
- 24 hours:
-
- eos6c02 tmp 83 > cat tomorrowtest
- #!/usr/gnu/bin/perl
- #
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
- localtime(time + 86400);
- printf "%02d%02d%02d %02d:%02d:%02d\n",
- $year+1900,
- $mon + 1,
- $mday,
- $hour,
- $min,
- $sec;
- eos6c02 tmp 84 > date
- Mon Nov 23 10:06:08 MET 1992
- eos6c02 tmp 85 > ./tomorrowtest
- 19921124 10:06:11
-
- More date like output is possible using string arrays. Date arrithmetic
- is also possible just by changing the value added to time above, 86400
- is the number of seconds in 1 day. Rather than a constant you could use
- an expression, you could even read the expression from the command line
- or input.
-
- N.B. the setting of TZ is a not a portable way to affect date:
-
- eos6c02 tmp 90 > date
- Mon Nov 23 10:12:11 MET 1992
- eos6c02 tmp 91 > ( setenv TZ MET-1MET ; date )
- Mon Nov 23 10:12:20 MET 1992
- eos6c02 tmp 92 > ( setenv TZ MET-25MET ; date )
- Mon Nov 23 09:12:25 MET 1992
-
- --
-
- Michael Salmon
-
- #include <standard.disclaimer>
- #include <witty.saying>
- #include <fancy.pseudo.graphics>
-
- Ericsson Telecom AB
- Stockholm
-