[LUGOS] Windows filetime -> time_t

Urban Purkat urban.purkat at hermes.si
Tue Aug 3 07:31:08 CEST 2004


> > UNIX maintains time in the form of a time_t, which represents
> > seconds since midnight, January 1, 1970, UTC.
> > Win32 maintains time primarily in the form of a FILETIME, which
> > represents 100-nanosecond intervals since January 1, 1601, UTC.
> 
> No, potem je trivialno, ce je oboje UTC.

Ja res je.

Resitev izgleda takole:

time_t ConvToTime_t(UInt64_t time) {
    const UInt64_t SECS_TO_FT_MULT(10000000);
    const UInt64_t TimeTBase(11644473600); // 1.1.1970
    ivd_Time32_t ret;
    if (time > UINT_MAX) {
        // It is Windows time
        // Conversion is needed
        ret = time/SECS_TO_FT_MULT - TimeTBase;
    }
    else {
        // It is Unix time
        ret = time;
    }
    return ret;
}

> > Malo me pa se bega: kaj je to filetime in systemtime?
> > A se sploh rabim ozirat na systemtime?
> 
> Ne, po moje je systemtime analogen localtime na unixih. Vse kar moras
> izracunat je time_t po tisti formuli ki jo je nasel google in zraven
> dodat UTC (skratka, pretvorit moras dobljeni timestamp v svoj casovni
> pas, to obicajno naredis s funkcijo localtime, glej man).

Nic ni treba konvertirat, ker sta FILETIME in time_t v UTC.

LP, U




More information about the lugos-list mailing list