freebsd version of 'data' for getting epoch time ... ?

Dan Nelson dnelson at allantgroup.com
Wed Jun 20 21:32:08 UTC 2007


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 at allantgroup.com


More information about the freebsd-questions mailing list