Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Tips] A Guide to Getting the Server Time with C++

Friday 28 August 2015
|
Read: Completed in minutes

[Tips] A Guide to Getting the Server Time with C++

You want to get server time to check something in your application, example check liscense key, time for used. This tips will be for you

A Guide to Getting the Server Time with C++








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

wYear
    The 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.





Remarks

It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you should

    Convert 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 ✋✋✋✋

🙇🏼 We Appreciate Your Comments and Suggestions - Webzone - all things Tech Tips web development 🙇🏼
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com