使用SYSTEMTIME,FILETIME和ULARGE_INTEGER修改日期和时间值 [英] Modifying the date and time values using SYSTEMTIME, FILETIME, and ULARGE_INTEGER

查看:293
本文介绍了使用SYSTEMTIME,FILETIME和ULARGE_INTEGER修改日期和时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2005用C ++编写一个程序,该程序需要在一组图像上创建带有时间的水印.

I am making a program, in C++ using Visual Studio 2005, that needs to create a watermark with the time on a set of images.

这些图像是从以特定时间间隔处理的视频中拍摄的.我想做的是通过SYSTEMTIME修改每个图像上的时间.我看了看MSDN,它说不要在SYSTEMTIME本身中修改值,而是先将其转换为FILETIME,然后转换为ULARGE_INTEGER.我的问题是ULARGE_INTEGER如何拆分?上半部分是日期,下半部分是时间,如果是这种情况,我该如何考虑过渡?就像是否有一张图片在2011年2月25日晚上11:58出现并一直持续到2011年2月26日12:11?当我将指定值转换回SYSTEMTIME变量时,是否会自动考虑并显示指定值?

These images are taken from a video that were processed at certain time intervals. What I am trying to do is to modify the time on each image through SYSTEMTIME. I looked at the MSDN and it says not to modify the values within SYSTEMTIME itself, but to convert it into a FILETIME and then an ULARGE_INTEGER. My question is how is the ULARGE_INTEGER split up? Is the HighPart the date and the Low Part the time and if that's the case how to I take into account rollover? Like if a image shows up at 11:58pm on 2/25/2011 and goes through until 12:11 2/26/2011? Would just adding the specified value automatically be taken into account and shown when I convert it back into a SYSTEMTIME variable?

预先感谢您的帮助.

推荐答案

他们建议将SYSTEMTIME转换为FILETIME,这是自一个纪元以来的多次滴答.然后,您可以添加所需数量的滴答声"(即100ns间隔)以表示您的您的时间,然后转换回SYSTEMTIME.

They suggest converting SYSTEMTIME to FILETIME, which is a number of ticks since an epoch. You can then add the required number of 'ticks' (i.e. 100ns intervals) to indicate your time, and convert back to SYSTEMTIME.

ULARGE_INTEGER结构是具有QuadPart成员的联合,该成员是64位数字,可以直接添加到(在最新的硬件上).

The ULARGE_INTEGER struct is a union with a QuadPart member, which is a 64bit number, that can be directly added to (on recent hardware).

SYSTEMTIME add( SYSTEMTIME s, double seconds ) {

    FILETIME f;
    SystemTimeToFileTime( &s, &f );

    ULARGE_INTEGER u  ; 
    memcpy( &u  , &f , sizeof( u ) );

    const double c_dSecondsPer100nsInterval = 100.*1.e-9;
    const double c_dNumberOf100nsIntervals = 
                    seconds / c_dSecondsPer100nsInterval;

    // note: you may want to round the number of intervals.
    u.QuadPart += c_dNumberOf100nsIntervals;

    memcpy( &f, &u, sizeof( f ) );

    FileTimeToSystemTime( &f, &s );
    return s;
 }

这篇关于使用SYSTEMTIME,FILETIME和ULARGE_INTEGER修改日期和时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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