英文:
Converting windows ticks into UNIX timestamp in Go
问题
我正在尝试将Windows Ticks转换为Go的本地time.Time
。具体来说,我想将635885625204626270
转换为UNIX时间戳。到目前为止,我只能适应一个PHP问题,并且只能得到秒数,但是我现在卡在这里。
ticksInUnix := (635885625204626270 / 10000000) - 60*60*24*365*1970
t := time.Unix(ticksInUnix, 0)
英文:
I am trying to convert Windows Ticks into Go's native time.Time
. Specifically, I want to convert 635885625204626270
into an UNIX timestamp. So far I only managed to adapt a PHP question, and could get as far as seconds, however I am now stuck here.
ticksInUnix := (635885625204626270 / 10000000) - 60*60*24*365*1970
t := time.Unix(ticksInUnix, 0)
答案1
得分: 1
尝试了很多方法来适应其他编程语言的答案后,我发现这是最准确的解决方案:
t := time.Unix(0, ((635885625204626270)-60*60*24*365*1970*10000000)*100)
这应该是最精确的解决方案,因为它不对原始的计时数进行除法运算,并且可以达到微秒级的精度(前提是Windows的计时数可以达到那么精确)。
英文:
After trying a lot to adapt answers in other programming languages, I found this to be the most accurate:
t := time.Unix(0, ((635885625204626270)-60*60*24*365*1970*10000000)*100)
It should be the most precise solution, as it does not perform divisions on the original tick count, and get to as accurate as microseconds (only if Windows can get that accurate on tick count, that is.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论