From owner-freebsd-questions@FreeBSD.ORG Thu Sep 17 05:47:02 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2414D1065672 for ; Thu, 17 Sep 2009 05:47:02 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from smtp.infracaninophile.co.uk (gate6.infracaninophile.co.uk [IPv6:2001:8b0:151:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id AFB168FC17 for ; Thu, 17 Sep 2009 05:47:01 +0000 (UTC) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [IPv6:::1]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.3/8.14.3) with ESMTP id n8H5klfQ002373; Thu, 17 Sep 2009 06:46:48 +0100 (BST) (envelope-from m.seaman@infracaninophile.co.uk) X-DKIM: Sendmail DKIM Filter v2.8.3 smtp.infracaninophile.co.uk n8H5klfQ002373 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infracaninophile.co.uk; s=200708; t=1253166408; bh=iSyqS6mkRCKZgVQv4YGgUmF/7MiHNPyfILcKAelbLTo=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Cc:Content-Type:Date:From:In-Reply-To: Message-ID:Mime-Version:References:To; z=Message-ID:=20<4AB1CD40.5020307@infracaninophile.co.uk>|Date:=20T hu,=2017=20Sep=202009=2006:46:40=20+0100|From:=20Matthew=20Seaman= 20|Organization:=20Infracaninophi le|User-Agent:=20Thunderbird=202.0.0.23=20(X11/20090823)|MIME-Vers ion:=201.0|To:=20Martin=20McCormick=20| CC:=20freebsd-questions@freebsd.org|Subject:=20Re:=20A=20question= 20about=20the=20date=20Function|References:=20<200909162025.n8GKP4 M6095537@dc.cis.okstate.edu>|In-Reply-To:=20<200909162025.n8GKP4M6 095537@dc.cis.okstate.edu>|X-Enigmail-Version:=200.95.6|Content-Ty pe:=20multipart/signed=3B=20micalg=3Dpgp-sha256=3B=0D=0A=20protoco l=3D"application/pgp-signature"=3B=0D=0A=20boundary=3D"----------- -enigEC0F0DB6067783BC8514F8A7"; b=S0fRLXrfJJ75qJ5fePPNec9xdurC6EpaDf3bdmVsU5xJMhEFdQggM6LCpmzLyt5li y+ObHvCx7geB2mI/wA3TFJ6sDghkcEEq9iDiVbRGniIb+UKJUmMvKwS3Hn7YGvvKCF MsIBXu8mlaiIXpr0kcypeFXqyvWm7fCeSgH7My/A= X-Authentication-Warning: happy-idiot-talk.infracaninophile.co.uk: Host localhost [IPv6:::1] claimed to be happy-idiot-talk.infracaninophile.co.uk Message-ID: <4AB1CD40.5020307@infracaninophile.co.uk> Date: Thu, 17 Sep 2009 06:46:40 +0100 From: Matthew Seaman Organization: Infracaninophile User-Agent: Thunderbird 2.0.0.23 (X11/20090823) MIME-Version: 1.0 To: Martin McCormick References: <200909162025.n8GKP4M6095537@dc.cis.okstate.edu> In-Reply-To: <200909162025.n8GKP4M6095537@dc.cis.okstate.edu> X-Enigmail-Version: 0.95.6 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigEC0F0DB6067783BC8514F8A7" X-Virus-Scanned: clamav-milter 0.95.2 at happy-idiot-talk.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED,NO_RELAYS autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on happy-idiot-talk.infracaninophile.co.uk Cc: freebsd-questions@freebsd.org Subject: Re: A question about the date Function X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2009 05:47:02 -0000 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--