Explore My Other Channel for More Cool and Valuable Insights
👉 Youtube Learn Tech Tips👉 Tiktok
👉 Facebook:We're using HttpQueryInfo for get server time,
using SystemTime for saving value datetime
SYSTEMTIME structure
Specifies a date and time, using individual members for the month, day, year, weekday, hour, minute, second, and millisecond. The time is either in coordinated universal time (UTC) or local time, depending on the function that is being called. Syntax C++
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
Members
wYearThe year. The valid values for this member are 1601 through 30827.
wMonth
The month. This member can be one of the following values.
Value Meaning
1 Jannuray
..
12 December
wDayOfWeek
The day of the week. This member can be one of the following values.
Value Meaning
0 Sunday
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
wDay
The day of the month. The valid values for this member are 1 through 31.
wHour
The hour. The valid values for this member are 0 through 23.
wMinute
The minute. The valid values for this member are 0 through 59.
wSecond
The second. The valid values for this member are 0 through 59.
wMilliseconds
The millisecond. The valid values for this member are 0 through 999.
Explore My Other Channel for More Cool and Valuable Insights
👉 Youtube Learn Tech Tips👉 Tiktok
👉 Facebook:Remarks
It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you shouldConvert the SYSTEMTIME structure to a FILETIME structure.
Copy the resulting FILETIME structure to a ULARGE_INTEGER structure.
Use normal 64-bit arithmetic on the ULARGE_INTEGER value.
The system can periodically refresh the time by synchronizing with a time source. Because the system time can be adjusted either forward or backward, do not compare system time readings to determine elapsed time. Instead, use one of the methods described in Windows Time.
Examples
The following example demonstrates how to using HttpQueryInfo
#include <WinInet.h>
/************************************************************************
Developer: zidane (huuvi168@gmail.com)
Last Modified: 2015-03-09
***********************************************************************/
SYSTEMTIME CAutoPlayDlg::GetServerTime()
{
// Clear output buffer
SYSTEMTIME sysTime;
SecureZeroMemory(&sysTime, sizeof(SYSTEMTIME));
// Open connection
HINTERNET hInternetSession = InternetOpen(NULL,
INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!hInternetSession)
return sysTime;
HINTERNET hInternetFile = InternetOpenUrl(hInternetSession,
L"https://learn-tech-tips.blogspot.com", 0, 0,
INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE, 0);
if (!hInternetFile)
{
InternetCloseHandle(hInternetSession);
return sysTime;
}
// Query date time in format systemtime
DWORD dwSize = sizeof(SYSTEMTIME);
if (!HttpQueryInfo(hInternetFile, HTTP_QUERY_DATE |
HTTP_QUERY_FLAG_SYSTEMTIME, &sysTime, &dwSize, NULL))
{
InternetCloseHandle(hInternetSession);
InternetCloseHandle(hInternetFile);
return sysTime;
}
// Clean up ...
InternetCloseHandle(hInternetFile);
InternetCloseHandle(hInternetSession);
return sysTime;
}
Any feedback for Get server time on above code, please leave your comment, I'll reply you as soon as I can
Reference for C# developer:
https://learn-tech-tips.blogspot.com/2018/02/get-server-time-using-c-sharp-dotnet.html
Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about
A Guide to Getting the Server Time with C++ ,
please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋
Webzone Tech Tips, all things Tech Tips for web development
- I am Zidane, See you next time soon ✋✋✋✋