Converting Unix time stamp to a date format.

Victor Odhner plug-discuss@lists.plug.phoenix.az.us
Wed, 15 Jan 2003 20:31:12 -0700


Here's a solution using the GNU "date" command,
which is extended beyond the original Unix date
command with all sorts of flexible formats and
function values.  See below.

If you're looking for how "localtime" and the
"date" command do this, for porting into XSLT
with no ability to call C or Perl code or commands,
I'm sure you can get the source for "localtime"
or "date" -- but I can't help you directly.

Good luck.

Carl Parrish wrote:
> Does anyone know where I can find the formula for converting a timestamp
> to a date format? I can't use any of the functions I typically would. I
> get the timestamp in an xml format. So far I can't find a xslt formula
> but I can hack one up in mozilla if I can figure out how. 
>  

 From "info date" on Linux:

If you're sorting or graphing dated data, your raw date values may
be represented as seconds since the epoch.  But few people can
look at the date `946684800' and casually note "Oh, that's the
first second of the year 2000 in Greenwich, England."

    date --date='2000-01-01 UTC' +%s
    946684800

To convert such an unwieldy number of seconds back to a more
readable form, use a command like this:

    # local time zone used
    date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
    1999-12-31 19:00:00 -0500

-- 

Vic

http://members.cox.net/vodhner/
   -- or --
http://www.newearth.org/~victor/resume.html