Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jun 2007 16:32:02 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Gore Jarold <gore_jarold@yahoo.com>
Cc:        questions@freebsd.org
Subject:   Re: freebsd version of 'data' for getting epoch time ... ?
Message-ID:  <20070620213202.GQ94657@dan.emsphone.com>
In-Reply-To: <925700.29847.qm@web63015.mail.re1.yahoo.com>
References:  <925700.29847.qm@web63015.mail.re1.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jun 20), Gore Jarold said:
> If I have a arbitrary date/time and I want to convert
> that to epoch time, I do this with GNU date:
> 
> date --date='1970-01-01 00:02:00 +0000' +%s
>
> Easy.
> 
> Can someone tell me what the syntax is for FreeBSD
> date command ?

date -j -f '%Y-%m-%d %H:%M:%S %Z' '1970-01-01 00:02:00 GMT' +%s

Adjust the -f argument to match whatever format your input string has
(the date manpage has an example that parses date's default output back
into itself).  Unfortunately, it looks like strptime doesn't handle the
%z flag, which is why I changed your +0000 to GMT and used %Z instead. 
%z is actually easier to parse, so I'm not sure why it's not handled.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070620213202.GQ94657>