免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6089 | 回复: 6
打印 上一主题 下一主题

请教 python如何表示以及处理C++中的FILETIME时间? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-23 15:03 |只看该作者 |倒序浏览
我在读取2进制文件数据时遇到了这个问题 (文件包含FILETIME数据) 只会用CTyte实现 但觉得那样不太好 想只用python自身函数类
高手能否讲解一下 最好以例说明 谢谢!

似乎 python和VC对 UTC的定义也不同 一个从1970/1/1 一个从1961/1/1 开始

[ 本帖最后由 yuntinghill 于 2006-1-23 15:45 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-01-23 20:12 |只看该作者
看不懂你的问题。请问什么是FILETIME数据呀。有个例子吗?到底想如何转换呢?

论坛徽章:
0
3 [报告]
发表于 2006-01-23 20:43 |只看该作者
lz说的应该是这个吧
FILETIME structure
http://msdn.microsoft.com/librar ... se/filetime_str.asp
http://vbworld.sxnw.gov.cn/vbapi/detail/FILETIME.htm

不知道Python for Win32 Extensions 里的win32file.GetFileTime是不是你要找的?

[ 本帖最后由 wolfg 于 2006-1-23 20:44 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2006-01-23 22:16 |只看该作者

回复 2楼 limodou 的帖子

union longtime{
        DWORD64        DwTime;
        FILETIME FlTime;
};

longtime Mytime;

for(int i=0;i<10;i++){
        GetSystemTimeAsFileTime( &(Mytime.FlTime) );
        printf("sysFiletime = %I64u \n",Mytime.DwTime);
}

此值与time.time() 所得值是不一样的(不仅单位不同)
当该值存入2进制文件 我想知道python 对此数据 如何解释处理 (使用那些类和函数)?
  
January 1, 1601                    The value 0 as a Win32 FILETIME.  
January 1, 1970                    The value -1 or 0 as a time_t.  

似乎 python 使用unix 的time_t  而vc的FILETIME使用Win32 FILETIME

谢谢两位!  我想斑竹所说的是我想要的办法 但那个扩展是需要另外下载吧 我怎么在python帮助中查不到?

[ 本帖最后由 yuntinghill 于 2006-1-23 22:31 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2006-01-24 08:45 |只看该作者
在python的os.path中有一些函数,不知道哪个是你可以使用的:


  1. getatime( path)

  2. Return the time of last access of path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible. New in version 1.5.2. Changed in version 2.3: If os.stat_float_times() returns True, the result is a floating point number.

  3. getmtime( path)

  4. Return the time of last modification of path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible. New in version 1.5.2. Changed in version 2.3: If os.stat_float_times() returns True, the result is a floating point number.

  5. getctime( path)

  6. Return the system's ctime which, on some systems (like Unix) is the time of the last change, and, on others (like Windows), is the creation time for path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible. New in version 2.3.
复制代码

论坛徽章:
0
6 [报告]
发表于 2006-01-24 09:18 |只看该作者
原帖由 yuntinghill 于 2006-1-23 22:16 发表
那个扩展是需要另外下载吧


是的。
http://starship.python.net/crew/mhammond/win32/Downloads.html

论坛徽章:
0
7 [报告]
发表于 2006-01-24 23:07 |只看该作者

大致解决 一个比较笨的方法

先计算出1961/1/1 到 1970/1/1的时间长度 记为time1970_1961 (单位 100纳秒)
然后对文件存储的每个FILETIME的时间数据-time1970_1961再除以10,000,000.0 得出 python所用的时间(UTC 1970/1/1,单位秒的float数据)
这时就可以用time.ctime ( (FILETIME的时间数据-time1970_1961)/1000000.0)

谢谢各位!扩展我正在看 希望有更简洁的方法
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP