gpt4 book ai didi

将 elisp unixtime 转换为 js-date 对象

转载 作者:行者123 更新时间:2023-11-30 15:45:43 25 4
gpt4 key购买 nike

对于特定应用程序,我需要在 Javascript 中处理 elisp 内部 unix 时间日期格式。 Elisp(当前时间)带有这种特殊格式:

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.

所以我得到一个时间字符串:[21039,58064,0]((21039 58064 0)的json表示)。我如何使用 javascript 将其转换为 JS Date 对象?在 emacs 中很容易,但这不是一个选择

最佳答案

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

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

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

关于将 elisp unixtime 转换为 js-date 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18856516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com