谁能举个例子从互联网上获取日期/时间,到目前为止我只使用 NetRemoteTOD 函数找到了信息。
但关键是我不知道如何使用它,服务器名称是什么。我刚刚在我的函数中尝试了以下代码,但它给出了运行时错误。
感谢帮助
LPTIME_OF_DAY_INFO pBuf = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
int CurrentYear ;
int CurrentMonth ;
int CurrentDay ;
int CurrentHour;
int CurrentMin;
pszServerName = (LPTSTR) "time.windows.com";
//
// Call the NetRemoteTOD function.
//
nStatus = NetRemoteTOD((LPCWSTR) pszServerName,(LPBYTE *)&pBuf);
//
// If the function succeeds, display the current date and time.
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
{
CurrentYear = pBuf->tod_year;
CurrentMonth =pBuf->tod_month;
CurrentDay = pBuf->tod_day;
CurrentHour=pBuf->tod_hours;
CurrentMin=pBuf->tod_mins;
}
}
//
// Otherwise, display a system error.
else
{
m_SharesEdit[9].SetWindowText("No time");
}
//
// Free the allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
if( CTime(CurrentYear,CurrentMonth,CurrentDay,CurrentHour,CurrentMin,0) >= CTime(2013,11,25,9,00,00) )
return true;
else
return false;