英文:
Convert windows time to timestamp
问题
我正在使用以下代码将Windows时间转换为Unix时间戳,
def convert_windows_time(windows_time):
return datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=windows_time / 10)
我该如何在Node.js中执行相同操作?以下方法不起作用,它导致了不同的日期:
let a = parseInt(129436810067618693)
let b = (new Date('1601-01-01').getMilliseconds()) + a / 10
console.log(new Date(b / 10000))
有任何想法是什么问题?
英文:
I'm using the following code to convert windows time to unix timestamp,
def convert_windows_time(windows_time):
return datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=windows_time / 10)
How can I do the same in nodejs? This does not work, it results in a different date:
let a = parseInt(129436810067618693)
let b = (new Date('1601-01-01').getMilliseconds()) + a / 10
console.log(new Date(b / 10000))
Any ideas what's wrong?
答案1
得分: 2
以下是翻译好的内容:
// 尝试以下代码:
const winepoch = new Date('1601-01-01T00:00:00.000Z').getTime();
const unxepoch = new Date('1970-01-01T00:00:00.000Z').getTime();
const difference = unxepoch - winepoch;
const a = 129436810067618693; // 以100纳秒为单位测量
console.log(new Date((a / 10000) - difference));
英文:
Try the following:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const winepoch = new Date('1601-01-01T00:00:00.000Z').getTime();
const unxepoch = new Date('1970-01-01T00:00:00.000Z').getTime();
const difference = unxepoch - winepoch;
const a = 129436810067618693; // measured in 100 ns
console.log(new Date((a / 10000) - difference));
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论