Date: Thu, 17 Sep 2009 06:46:40 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Martin McCormick <martin@dc.cis.okstate.edu> Cc: freebsd-questions@freebsd.org Subject: Re: A question about the date Function Message-ID: <4AB1CD40.5020307@infracaninophile.co.uk> In-Reply-To: <200909162025.n8GKP4M6095537@dc.cis.okstate.edu> References: <200909162025.n8GKP4M6095537@dc.cis.okstate.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigEC0F0DB6067783BC8514F8A7 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Martin McCormick wrote: =20 > date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s" >f0 > date +%s >f1 > What does the long form of this command give us that > date +%s fails to do? It's a contrived example: date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"=20 -j says "don't alter the system date" -- this is used if you want to read and format a date/time string other than the present time. -f says use the following format to read the input date. That's %a -- abbreviated weekday name (localized) %b -- abbreviated month name (localized) %d -- day of month as decimal number, zero padded to two digits %T -- equivalent to %H:%M:%S %H -- Hour in 24h clock, zero padded to two digits %M -- Minute, zero padded %S -- Second, zero padded %Z -- Time zone name %Y -- Year as 4 digits including century. (See strftime(3)) Which looks like this: % date +"%a %b %d %T %Z %Y" Thu Sep 17 06:31:15 BST 2009 and that just happens to be the default *output* format date produce= s without any arguments. Which is appropriate as the next item on the= command line is "`date`" Rune the date command without arguments and substitute the ou= tput into the command line here as a single argument +%s finally, says output the date that was read in as the number of se= conds since the epoch. This is an argument to the initial date command. so the end result is that the command reads the current date time in the = standard output format, parses all of that then converts it into seconds-since-the= -epoch, using two invocations of the date(1) program to do so. Which is not at al= l efficient if all you need to do is generate the current epoch time. Just use date +%s for that. On the other hand, it does show you how to convert an arbitrary date/time= to=20 epoch time. eg.: % date -j -f "%a %b %d %T %Z %Y" "Fri Feb 13 23:31:30 GMT 2009" +%s 1234567890 Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enigEC0F0DB6067783BC8514F8A7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAkqxzUcACgkQ8Mjk52CukIzYvwCfel77w5JPlqr7UBE1s+deYALS llcAn0WNlNerblTjPovf1LQvNWB4eLW2 =byaT -----END PGP SIGNATURE----- --------------enigEC0F0DB6067783BC8514F8A7--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4AB1CD40.5020307>