0

for a specific application I need to handle elisp internal unix time date format in Javascript. Elisp (current-time) comes with this special format:

current-time is a built-in function in `editfns.c'. (current-time)

Return the current time, as the number of seconds since 1970-01-01 00:00:00. The time is returned as a list of integers (HIGH LOW USEC PSEC). HIGH has the most significant bits of the seconds, while LOW has the least significant 16 bits. USEC and PSEC are the microsecond and picosecond counts.

So i´m getting a time string: [21039,58064,0] (json representation of (21039 58064 0)). How can i convert this into a JS Date Object with javascript? Its easy in emacs, but this is not an option

4

1 回答 1

1
Date(21039 * Math.pow(2, 16) + 58064);

请注意,您不需要完全这样写,Math.pow(2, 16)因为这是一个常量表达式。这样您就可以了解发生了什么。

另请注意,您不能对浮点数使用按位运算(Number在 JavaScript 用语中 s 大于 2^32)。所以你必须相乘而不是移位和求和而不是“或”。

于 2013-09-17T19:58:18.300 回答