Originally Posted by
carlyn
yes... actually i have this device that go under testing. so each time, i will need to manually change the time and date of that device to syn. with my pc local time. but indeed of using local pc time, I will wish to use the server time so it will be more accurate as local pc time might be changed by others and incorrect!
so basically i am developing a program that will automatically take the time from server and update the the device.
I have ady get this function
NetRemoteTOD
but somehow it could work with my compiler...
any idea?
Possibly?
Code:
#pragma comment(lib, "netapi32.lib")
#include <stdio.h>
#include <windows.h>
#include <lm.h>
static const char *dow[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static const char *month[] = { "???", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
int main( int argc, char *argv[] )
{
wchar_t server[256] = L"";
TIME_OF_DAY_INFO *p = NULL;
if ( argc > 1 )
mbstowcs( server, argv[1], strlen( argv[1] ) + 1 );
else
return -1;
if(NetRemoteTOD( server, (LPBYTE *) &p ) != NERR_Success)
return -1;
printf( "Unix time_t: %lu (since 1/1/70 00:00:00 UTC)\n", p->tod_elapsedt );
printf( "Milliseconds: %lu (since boot)\n", p->tod_msecs );
printf( "Current time: %02lu:%02lu:%02lu.%02lu (UTC)\n", p->tod_hours, p->tod_mins, p->tod_secs, p->tod_hunds );
printf( "Timezone offset: %ld (minutes from GMT)\n", p->tod_timezone );
printf( "Tick length: %lu (microseconds)\n", p->tod_tinterval * 100 );
printf( "Current date: %s, %lu %s %lu\n", dow[p->tod_weekday], p->tod_day, month[p->tod_month], p->tod_year );
NetApiBufferFree( p );
return 0;
}