将Unix/Linux时间转换为Windows时间的方法

将Unix/Linux时间转换为Windows时间的方法,windows,linux,ms-office,datetime,Windows,Linux,Ms Office,Datetime,我想在两个系统上都有很多方法在两者之间转换。我正在寻找一个快速简单的方法来做到这一点 我想要Python方式、excel、openoffice计算方式、access方式、命令行方式。任何其他的方法,你这样做也会很好。换一种方式(从Windows到Linux)也不错 我有一些脚本的输出,其中包括1970年以来以秒为单位的时间,但我想转换为Windows时间。这样,当它被导入到数据库中时,就不会弄乱时间 在Linux中,您可以使用gettimeofday从1970年1月1日起以微秒(10^-6秒)为

我想在两个系统上都有很多方法在两者之间转换。我正在寻找一个快速简单的方法来做到这一点

我想要Python方式、excel、openoffice计算方式、access方式、命令行方式。任何其他的方法,你这样做也会很好。换一种方式(从Windows到Linux)也不错

我有一些脚本的输出,其中包括1970年以来以秒为单位的时间,但我想转换为Windows时间。这样,当它被导入到数据库中时,就不会弄乱时间

在Linux中,您可以使用gettimeofday从1970年1月1日起以微秒(10^-6秒)为单位获得时间

Windows中包含一个64位值,表示自1601年1月1日(UTC)以来的100纳秒间隔数

这里有一条C路

从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
中介绍了这一点,其中提供了示例C代码

总结:

filetime = (unixtime * 10000000) + 116444736000000000

0x3DE43B0C → 0x01C295C4:91150E00 (2002-11-27 03:25:00 +0000)
(这也很有帮助。)



通常,使用
strtime()
或类似方法更容易解析人类可读的时间戳,例如“2002-11-27 03:25:00”(printf
%AF%AT
),在office中,您可以使用我从open office fourms获得的这个FOMRule进行转换。 开放办公室

(unix时间/86400)+25569=您的日期

取(unix时间1300973245.0592268670/秒/天(86400))+25569(自1899年以来的天数)=(40626.5607) 2011/03/2413:27:24

打开office日期很容易计算,将0放在列中并将其格式化为最新日期

0=1899/12/30 00:00:00
25569=1970/01/01 00:00:00#自1899年至1970年的天数
40626.5607=2011/03/24 13:27:24

我预计2007年的office也会如此,但

0=1900/01/00:00
365=1900/12/30 00:00
25569=1970/01/01 00:00#哪个是相同的

我不知道为什么open office中的0日期与windows中的不同。现在唯一的问题是,它的报告时间比以前少了2年。然后是创建文件的实际日期。应该说是2009年,而不是2011年

这是“查找”命令提取访问日期而不是创建日期的问题

查找./sd-mmc-card/-iname*.jpg-printf“%h/%f\t%f\t%a\t%Ax\t%AT\t%a@\n”

它应该是%t和%t@这两个\t是选项卡

查找./sd-mmc-card/-iname*.jpg-printf“%h/%f\t%f\t%t\t%t@\n”

出于某种原因,上述公式从创建时间起下降了两个小时

星期五3月27日17:08:18.0000000000 2009 | 2009/03/27 15:08:18

所以我只需在公式中加上0.08333(2小时)

(unix时间/86400)+25569+0.08333=您的日期


我一直在寻找类似的东西(在Windows和Linux时代/年代之间进行转换),最后用MSDN和Microsoft的一些东西编写了一些东西

这很自然地使用Win32从Linux复制了
gettimeofday()

#include <windows.h>
/**
 * number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
 */
#define EPOCH_DIFF 11644473600LL

void gettimeofday(ULARGE_INTEGER* microsecondsAsULINT)
    {
        FILETIME ftTime;
        SYSTEMTIME stTime;

        // Get the current system time
        GetSystemTime(&stTime);
        // Convert it to filetime which is # of 100ns periods since Jan 1, 1601
        SystemTimeToFileTime(&stTime, &ftTime);
        // Move it into the return result
        microsecondsAsULINT->HighPart = ftTime.dwHighDateTime;
        microsecondsAsULINT->LowPart = ftTime.dwLowDateTime;
        // Convert to UTC by subtracting epoch difference as 100ns periods
        microsecondsAsULINT->QuadPart -= (EPOCH_DIFF*10000000);
        // Convert to microseconds ([# of 100ns periods]/10 = [# of 1us periods])
        microsecondsAsULINT->QuadPart = microsecondsAsULINT->QuadPart/10;
    }
#包括
/**
*从1601年1月1日00:00到1970年1月1日00:00 UTC的秒数
*/
#定义EPOCH_DIFF 116444473600LL
void gettimeofday(ULARGE_整数*微秒asulint)
{
文件时间;
系统时间stTime;
//获取当前系统时间
GetSystemTime(&stTime);
//将其转换为filetime,即自1601年1月1日起的100ns周期
SystemTimeToFileTime(&stTime,&ftTime);
//将其移动到返回结果中
微秒asulint->HighPart=ftTime.dwHighDateTime;
微秒Asulint->LowPart=ftTime.dwLowDateTime;
//将历元差减去100ns周期,转换为UTC
微秒asulint->QuadPart-=(历元差值*10000000);
//转换为微秒([#100ns周期]/10=[#1us周期])
微秒asulint->QuadPart=微秒asulint->QuadPart/10;
}
编辑:二读时有几条在线评论不清楚;已更新(还天真地将umlauts添加到“i”中)。

BOOL PbyteTimeToUnixTime(PBYTE pTime,LONGLONG*pUnixTime)
{
系统时间stSystemTime;
文件时间stFileTime;
//转换系统时间
memset(&stSystemTime,0,sizeof(stSystemTime));
stSystemTime.wYear=((pTime[0]文件时间)変換
if(SystemTimeToFileTime(&stSystemTime,&stFileTime)==FALSE){
返回FALSE;
}
//FILETIME->UNIXTIME
*pUnixTime=stFileTime.dwHighDateTime;

*在linux中,您可以执行以下操作:

以秒为单位的unix时间戳

date -d @1267619929  
Wed Mar  3 14:38:49 SAST 2010
unixtime戳记的日期字符串

date -d 2016-08-09 +%s  
1470693600
取自

然后应用其他帖子中的数学公式,得到在MS office中识别的日期值

echo $(( $(date -d '2016-08-08T00:00:00-0000' +%s) / 86400 + 25569 ))  
42590  

微软有额外的闰年来保持兼容性,这就是为什么OpenOffice比微软早一年启动的原因。