04-25-04 08:34 PM
Gnarlodious <gnarlodiousNULL@VOID.invalid.yahoo.com> writes:
> Is there a shell command to return seconds since 1/1/1970?
This has come up enough that I've added the following to the FAQ under
the date arithmetic section:
h. Getting the number of seconds since the epoch
GNU date has the %s format option which returns the epoch
time. More portably, use awk
awk 'BEGIN {srand();print srand()}'
This works because srand() sets its seed value with the current
epoch time if not given an argument. It also returns the
previous seed value, so the second call gives the epoch time.
Depending on scheduling, when the call is actually executed,
etc, this might be off by a second.
Another way is to use PERL if you have it.
perl -e 'print time,"\n"'
Comments would be welcome before committing this.
Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
[ Post a follow-up to this message ]
|