Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #168195

Re: what is the best way to get microseconds of time on Windows in C or C++ ?

From Andreas <nospam@gmx.de>
Newsgroups comp.lang.c, comp.lang.c++
Subject Re: what is the best way to get microseconds of time on Windows in C or C++ ?
Date 2022-11-16 13:15 +0100
Organization A noiseless patient Spider
Message-ID <tl2k84$2beqi$1@dont-email.me> (permalink)
References <tk1p0t$1iv03$1@dont-email.me> <KG89L.4244$KkB2.2249@fx47.iad> <tkuh77$1rt0u$1@dont-email.me> <87zgctj8wz.fsf@nosuchdomain.example.com> <tl176i$25jh1$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


Am 16.11.2022 um 00:26 schrieb Lynn McGuire:
> This works fine for me:
> 
>      //  from:
>      // 
> https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows
> 
> struct timezone {
>      int tz_minuteswest;
>      int tz_dsttime;
> };
> 
> int mygettimeofday (struct timeval *tv, struct timezone *tz)
> {
>      if (tv) {
>          FILETIME               filetime; /* 64-bit value representing 
> the number of 100-nanosecond intervals since January 1, 1601 00:00 UTC */
>          ULARGE_INTEGER         x;
>          ULONGLONG              usec;
>          static const ULONGLONG epoch_offset_us = 11644473600000000ULL; 
Wrong value. Correct value is 116444736000000000ULL (9 trailing zeros).

Rough estimation (1970-1601)*365*24*60*60 = 11'636'784'000 seconds 
(ignoring Feb 29 in leap years). Additional 6 zeros to convert seconds 
to microseconds.


> /* microseconds betweeen Jan 1,1601 and Jan 1,1970 */
> 
> #if _WIN32_WINNT >= _WIN32_WINNT_WIN8
>          GetSystemTimePreciseAsFileTime ( & filetime);
> #else
>          GetSystemTimeAsFileTime ( & filetime);
> #endif
>          x.LowPart =  filetime.dwLowDateTime;
>          x.HighPart = filetime.dwHighDateTime;
>          usec = x.QuadPart / 10  -  epoch_offset_us;
>          tv->tv_sec  = (time_t) (usec / 1000000ULL);
>          tv->tv_usec = (long) (usec % 1000000ULL);
>      }
>      if (tz) {
>          TIME_ZONE_INFORMATION timezone;
>          GetTimeZoneInformation(&timezone);
>          tz->tz_minuteswest = timezone.Bias;
>          tz->tz_dsttime = 0;
>      }
>      return 0;
> }
> 
> Thanks,
> Lynn
> 

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-03 20:14 -0500
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? DFS <nospam@dfs.com> - 2022-11-03 21:51 -0400
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 00:06 -0500
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Christian Gollwitzer <auriocus@gmx.de> - 2022-11-04 08:03 +0100
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:32 -0500
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-04 09:07 -0700
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:33 -0500
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Opus <ifonly@youknew.org> - 2022-11-06 20:53 +0100
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Juha Nieminen <nospam@thanks.invalid> - 2022-11-04 07:35 +0000
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:24 -0500
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-04 19:50 +0000
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 15:16 -0500
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-04 15:05 -0700
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 17:35 -0500
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-04 15:56 -0700
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-04 16:15 -0700
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? scott@slp53.sl.home (Scott Lurndal) - 2022-11-04 13:44 +0000
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:34 -0500
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-14 16:58 -0600
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-14 17:36 -0800
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-15 17:26 -0600
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? Andreas <nospam@gmx.de> - 2022-11-16 13:15 +0100
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-04 20:49 +0100
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Bart <bc@freeuk.com> - 2022-11-04 22:31 +0000
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-05 06:40 +0100
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Manu Raju <MR@invalid.invalid> - 2022-11-20 21:30 +0000

csiph-web