Sync device Date/Time with http web server
Well, this is long way back when I was a rookie to develop Windows Mobile applications with C#.
I believe there are some people want to sync the device date/time with their web server as the device date/time somehow doesn't tick correctly after certain days. So first of all, you should have a look the SetSystemTime function as you need a SYSTEMTIME structure to pass the value to SetSystemTime function.
We start to P/Invoke the SetSystemTime method.
Create the SYSTEMTIME structure.
Create a simple function to convert DateTime to SYSTEMTIME and also calls the SetSystemTime function.
As most http web pages contains "Date" part of the document header and the "Date" part usually is the server time. So we gets the date/time and sync with our device. We use HttpWebRequest and HttpWebResponse to get the web page header.
Above method has few millisecond or event seconds inaccuracy as we doesn't calculate the time difference from request to response. However, it is quite good enough for many customers. Ha... I am lazy again...
Related Posts
In case you missed it
A short update from me
It has been a while since I post a blog page on Blogger which was created back in 2013. So I took an opportunity to...
Showcase the blog site elements
The standard paragraphs Welcome to this demo page! Here, you’ll get an exclusive preview of our cutting-edge platform designed to revolutionise your digital experience. Our...
Issue with "Don't track your own pageviews"
Do you use your own domain name with Blogger? Do you place “Blogger’s Stats Widget” on your page? Or do you regularly check up the...