I want to sync the clock of a remote device with another device, without continuously requesting the time of the remote device.
I want to know the difference between the time on my device and the remote device, so I can add the timestamp of the remote device to an event.
The solution that I have so far is: Get the time of the remote device and calculate the difference by making a comparison.
For example:
DateTime myDevice = DateTime.Now();
DateTime remoteDevice = getDateTimeOfRemoteDevice();
//Compare the clocks and keep the difference...
int daydiff = myDevice.Day - remoteDevice.Day
int monthdiff = myDevice.Month - RemoteDevice.Month
// ...and so on un till i have everything separated.
My question is: is there a better way to do this?
Perhaps something like: DateTime difference = DateTimeRemoteDevice - DateTimeMyDevice;
, where the answer is: 00/00/00 00:01:50
, which would allow me to recalculate at any time the time on the remote device (including the days month and year difference).