[exslt] Milliseconds since 1970-01-01T00:00:00Z ?

Jeni Tennison jeni at jenitennison.com
Thu Nov 22 07:08:57 MST 2001


Hi Dan,

> I need to convert between an integer number of milliseconds since
> 1970-01-01T00:00:00Z and a formatted date string. I searched archive
> and date-time library and can't quite see exactly what I am looking
> for. There was only one comment by Jeni in the archives addressing
> this:
>
>  "JavaScript's Date.getTime(), Java's Date.getTime() and Java's
>   GregorianCalendar.getTimeinMillis all return the number of
>   milliseconds since 1970-01-01T00:00:00Z.  Perhaps there should be a
>   separate date:unix-time() or something function to give that kind of
>   functionality?"
>
> Can someone clear me up if this is possible with the existing
> library? I probably could settle for seconds to date conversion but
> I need to go in both directions:
>
>   CCYY-MM-DDThh:mm:ss -> intMilliseconds
>   intMilliseconds -> CCYY-MM-DDThh:mm:ss

The quote, I think, was in response to Mike suggesting that
date:seconds() return seconds since some other epoch rather than
1970-01-01T00:00:00Z, but as it stands we haven't changed
date:seconds(). You should be able to use:

  date:seconds($dateTimeString) * 1000

to get milliseconds. There's a JavaScript version of this function.
I've almost completed an XSLT function/template version, but there are
still a few things to sort out with it.

For milliseconds *to* a dateTime, you can convert the milliseconds
into a duration with date:duration() and then add that duration to
1970-01-01T00:00:00Z with date:add():

  date:add('1970-01-01T00:00:00Z',
           date:duration($milliseconds div 1000))

Again, there are JavaScript versions of both these functions, courtesy
of Chris. There are also XSLT template/functions for them.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/




More information about the exslt mailing list