Modifying the date and time values using SYSTEMTIME, FILETIME, and ULARGE_INTEGER

*爱你&永不变心* 提交于 2019-12-06 22:43:07

问题


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.

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?

Thanks in advance for your help.


回答1:


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.

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;
 }


来源:https://stackoverflow.com/questions/5118411/modifying-the-date-and-time-values-using-systemtime-filetime-and-ularge-intege

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!