将Unix / Linux时间转换为Windows时间的方法 [英] Ways to Convert Unix/Linux time to Windows time

查看:496
本文介绍了将Unix / Linux时间转换为Windows时间的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个系统之间进行两种转换。我正在寻找一个快速和容易的方式来做到这一点。



我想要Python的方式,excel,openoffice calc方式,访问方式,命令行方式。你做的其他任何方式也是不错的。从另一个方面(从Windows到Linux)也是很好的



我有一些脚本的输出,包括自1970年以来的几秒钟的时间,但是我想转换为Windows时间。所以当它被导入到一个数据库它不会弄乱时代。


在Linux中,您可以从1970年1月1日起使用gettimeofday获取时间(10 ^ -6秒)。



在Windows中包含一个64位值,表示从1601年1月1日(UTC)起的100纳秒间隔数。


这是一种C方式。 http://stackoverflow.com/questions/3585583/convert-unix-linux- time-to-windows-filetime



示例从find

 code> find ./sd-mmc-card/ -iname * .jpg -printf%h /%f\t%f\t%a\t%Ax\t%AT\t %A @ \\\
> dbtime.txt

./sd-mmc-card/0117.jpg 0117.jpg Thu Mar 24 15:27:25.0059226867 2011 24/03/2011 15:27:25.0592268670 1300973245.0592268670


解决方案

这是在将time_t值转换为文件时间,它提供样本C代码。



摘要:

  filetime =(unixtime * 10000000)+ 116444736000000000 

0x3DE43B0C→0x01C295C4:91150E00 2002-11-27 03:25:00 +0000)

(同样有用的是如何从相当长的时间内识别不同类型的时间戳 。)






通常更容易解析人类可读的时间戳,例如2002-11-27 03: 25:00(printf %AF%AT ),使用 strptime()或类似的。 / p>

I want many ways to convert between the two on both systems. I am looking for a quick and easy way to do this.

I would like Python ways, excel, openoffice calc ways, access ways, command line ways. Any other way that you do it would be nice as well. Going the other way (from Windows to Linux) would also be nice

I have output from some of my scripts that include the time in seconds since 1970, but I want to convert to Windows time. So that when it gets imported into a database it does not mess up the times.

In Linux you can obtain time in microseconds (10^-6 sec) from 1 Jan 1970 using gettimeofday.

In Windows Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

Here is a C way. http://stackoverflow.com/questions/3585583/convert-unix-linux-time-to-windows-filetime

Example out put from find

find ./sd-mmc-card/ -iname *.jpg -printf "%h/%f\t%f\t%a\t%Ax\t%AT\t%A@\n" > dbtime.txt

./sd-mmc-card/0117.jpg    0117.jpg    Thu Mar 24 15:27:25.0059226867 2011    24/03/2011    15:27:25.0592268670    1300973245.0592268670

解决方案

This is described in Converting a time_t Value to a File Time, which provides sample C code.

Summary:

filetime = (unixtime * 10000000) + 116444736000000000

0x3DE43B0C → 0x01C295C4:91150E00 (2002-11-27 03:25:00 +0000)

(Also helpful is How to recognize different types of timestamps from quite a long way away.)


Often it is easier to parse the human-readable timestamp, such as "2002-11-27 03:25:00" (printf %AF %AT), using strptime() or similar.

这篇关于将Unix / Linux时间转换为Windows时间的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆