26
Dec
gettimeofday function for windows
Related Blog Items
- Displaying execution time of a program
- c/c++ blogging - January 10, 2007
- Pelt: Posix Wrapper for Windows Threads
- dlwrapper: POSIX Wrapper for Windows Dynamic Library Loading Calls
- A simple window application
The gettimeofday() function obtains the current time, expressed as seconds and microseconds since the Epoch, and store it in the timeval structure pointed to by tv. As posix says gettimeoday should return zero and should not reserve any value for error, this function returns zero. Here is the program, I?ve given definition struct timezeone and for others I didn?t give as all other data types definitions are available in windows include files itself.
#include < time.h > #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #else #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL #endif struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; int gettimeofday(struct timeval *tv, struct timezone *tz) { FILETIME ft; unsigned __int64 tmpres = 0; static int tzflag; if (NULL != tv) { GetSystemTimeAsFileTime(&ft); tmpres |= ft.dwHighDateTime; tmpres <<= 32; tmpres |= ft.dwLowDateTime; /*converting file time to unix epoch*/ tmpres /= 10; /*convert into microseconds*/ tmpres -= DELTA_EPOCH_IN_MICROSECS; tv->tv_sec = (long)(tmpres / 1000000UL); tv->tv_usec = (long)(tmpres % 1000000UL); } if (NULL != tz) { if (!tzflag) { _tzset(); tzflag++; } tz->tz_minuteswest = _timezone / 60; tz->tz_dsttime = _daylight; } return 0; }
usage:
struct timeval now; struct timezone tzone;
gettimeofday(&now, NULL);
gettimeofday(&now, &tzone);
download [gettimeofday.c] program..
Popularity: 87%
You need to log on to convert this article into PDF
Related Blog Items - Displaying execution time of a program
- c/c++ blogging - January 10, 2007
- Pelt: Posix Wrapper for Windows Threads
- dlwrapper: POSIX Wrapper for Windows Dynamic Library Loading Calls
- A simple window application
Related Blog Items
- Displaying execution time of a program
- c/c++ blogging - January 10, 2007
- Pelt: Posix Wrapper for Windows Threads
- dlwrapper: POSIX Wrapper for Windows Dynamic Library Loading Calls
- A simple window application
[…] OpenAsthra presents gettimeofday function for windows posted at OpenAsthra, saying, “gettimeofday function for windows” […]
January 6th, 2007 at 6:51 pm
[…] refer another post for gettimeofday […]
April 15th, 2007 at 6:27 pm
very useful post, saved me a lot of time, I’d searched the net could not find a working program, at last found here, and without tweaking a bit it worked straight away, thanks
December 29th, 2007 at 4:35 pm
one would think conversion to usecs goes before adjusting by DELTA_EPOCH_IN_MICROSECS (really in microsecs- 8 zeroes 6 from micro, 2 from 60*60*24 -whole day)
January 11th, 2008 at 1:06 pm
Thanks for pointing this out, I’d corrected the code
January 11th, 2008 at 6:28 pm
Out Source Data Entry, Data Conversion jobs to India…
“One of the big advantages to outsourcing is flexibility–it can be a lot easier to cut back on a vendor than an employee. (Think of how you would feel if you had to tell an employee who is dependent on their job that you only need them half-time now….
March 16th, 2008 at 9:12 pm
great article!
thanks, this saved me some time!
June 23rd, 2008 at 2:30 pm
natural male enhancement…
Send a message Subscribe to RSS feed Tell a friend Add to My MSN Add to Live….
June 27th, 2008 at 12:40 am
I have recently created a website devoted to helping people find real work at home jobs. I muddle through the hype and give an honest review of the programs that will actually put cash in your pockets. Please check it out you will not be diappointed. Any feedback is always welcome.
Thank You,
Sam
www.HomeJobs4u.net
July 17th, 2008 at 7:21 pm