Google Search Results
You arrived here after searching for the following phrases:
Click a phrase to jump to the first occurrence, or return to the search results.
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..
Related posts:
[...] OpenAsthra presents class=”searchterm1″>gettimeofday function for windows posted at OpenAsthra, saying, “class=”searchterm1″>gettimeofday function for windows” [...]
[...] refer another post for class=”searchterm1″>gettimeofday [...]
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
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)
Thanks for pointing this out, I’d corrected the code
great article!
thanks, this saved me some time!
Hi dear ,
Some really helpful information here. I Like of your website design . Did you make this templete yourself or did you get it from any templetes websites? Looks pretty cool for me . I use Joomla but wants something better.
Hey, thanks a lot for the information post . I have wondering if you make money from pay per post too? I heard that is not bad for a good page rank blog.
Hey , I finally decided to write a comment on your blog . I just wanted to say good job . I really enjoy reading your posts.
Hey, many thanks, this was exactly what I needed at 3am to get my unix
app working under Win32. Many MANY thanks!
Rich
Very, very useful.
Thnky you, for an excellent post