-----BEGIN PGP SIGNED MESSAGE----- "Daniel R. Oelke" <droelke@rdxsunhost.aud.alcatel.com> writes:
someone, probably either patrick@Verity.COM or hallam@w3.org, writes:
Piete.Brooks@cl.cam.ac.uk, stripes@va.pubnix.com writes:
I'd like to get the raw date in brloop (a sh script). In perl I'd just use "time", and I can't see a way to get "date +" to yield the raw time. I could use "date=`perl -e 'print time'`" but that seems OTT, and perl may not be on teh users PATH. Any suggestions ?
"date '+%s'" does it under BSDI, but I'm not sure how portable it is.
That doesn't work under SunOS 4.1.x, but this does:
date "+%S %M 60 * + %H 3600 * + %j 86400 * + %y 31536000 * + p" | dc
This assumes 365 days/year, so if you jump from a leap year to a non-leap year it won't work right. Hey - a 1/1460 failure rate is better than most Windoze programs I've used ;-)
It also isn't the "absolute" time, (as given by time()), but gives a number of seconds that constantly increases.
With a little more work you should be able to adjust this to be close to time() functionality.
This was, of course, originally one long line: date +"%S %M 60 * + %H 3600 * + %j 1 - 86400 * + %y 70 - 31536000 * + %y 69 - 4 / 86400 * + 3600 4 * + p" |dc Differences: %j 1 -, because days of the year are numbered from 1, not zero, and we don't want to count 86400 seconds for today before today has finished. %y 70 -, because 1970 is the epoch, of course. %y 69 - 4 / 86400 * +, takes into account all leap days in all leap years up through last year. Why? Left as an exercise for the reader. ;-) 3600 4 * +, this is a bit of ugliness. date +%s returns GMT for me. I'm in EDT, so that's four hours away from GMT. So this is necessary to make this return the same number as date +%s. But if you're in another time zone, you need to change that 4 above appropriately. If this whole section is deleted we are left with: date +"%S %M 60 * + %H 3600 * + %j 1 - 86400 * + %y 70 - 31536000 * + %y 69 - 4 / 86400 * + p" |dc which returns local time, which is probably what you wanted anyway. By the way, date --version, on my system, returns "GNU shellutils 1.9.4", just in case you were wondering what date I'm using. -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQCVAwUBMEKT+REcrOJethBVAQEXgAQAx9HLiR+LPvclEYRFrliqOugj9cbzGwLD HCWOC8/MfrXuS3MPLQj1HugA18LH/LGy3BTp7cSnSNXDoL2/7UkLeAspGejRrEG4 WgQ8HIC2weVDP66PqioFD6lAELatRWk4Xl/mLgVrxluBrKtRnADtCX/VdHPw1ZiU YDfiWBtKRGU= =i1Di -----END PGP SIGNATURE----- -- David R. Conrad, ab411@detroit.freenet.org, http://www.grfn.org/~conrad Finger conrad@grfn.org for PGP 2.6 public key; it's also on my home page Key fingerprint = 33 12 BC 77 48 81 99 A5 D8 9C 43 16 3C 37 0B 50 Jerry Garcia, August 1, 1942 - August 9, 1995. Requiescat in pace.
participants (1)
-
ab411@detroit.freenet.org