[CLUE-Talk] Timestamps N' More

Tom Poindexter tpoindex at nyx.net
Wed Nov 1 12:37:07 MST 2000


On Wed, Nov 01, 2000 at 11:54:59AM -0700, Jeremiah Stanley wrote:
> I need a good definition of UNIX timestamps and how they work. I am trying
> to find the difference in minutes between two timestamps and cannot find a
> good enough definition for this.

Unix timestamps, or more appropriately 'unix time values' (the value returned
by the time() system call) are indeed the number of seconds since epoch.  
If you want the number of minutes between two timestamps:

	(t1 - t2) / 60

Epoch is defined as 00:00:00 January 1, 1970 UTC, so remember to apply
local timezone offsets if that matters to you.  With signed 32 bit time values,
the Unix timestamp will reach it's "y2k" problem on Jan. 18, 2038.

Of course by then, 32 bit processors will only exist in museums, and we'll
be running on 1024 bit processors :)

I'll leave you with a bit of code that I came up with a while back that
prints the timestamp of a file, something that is often needed in shell
scripts that don't have access to the stat() system call:

#!/bin/sh
# timestamp.sh
# print the unix time of a file

# to test the biggest timestamp:
# touch -t 203801182014.07 junk

if test ! -f "$1" ; then
    echo "whoops, file \"$1\" doesn't exist"
    exit 1
fi

bc <<__EOF__
ibase=8
`( echo $1 | cpio -o -H odc | dd bs=1 skip=48 count=11 ) 2>/dev/null`
__EOF__

# finis







 

-- 
Tom Poindexter
tpoindex at nyx.net
http://www.nyx.net/~tpoindex/



More information about the clue-talk mailing list