There is this API that when called gives me the time of a remote server. This is the response JSON of that API:
{
hour: 12,
minute: 2,
second: 20,
msFormat: "/Date(1590478340707)/"
}
This time is not in sync with the server my code runs on. And I need milliseconds precision for my code according to time of the remote server.
I want to call another API of that server, exactly based on some time relative to that server. Thus I can't use DateTime.Now
of my own server, because they are not in sync. My server and the remote server have the same year, same month, same day, but they might sometimes even be off by hours.
I saw this question, but answers assume that I have access to JavaScript code on that server to get time. I don't. I also saw this question, but it's about sending my own client's time to my server. And as I said, I don't have access to creation of JavaScript's datetime. I only have access to data shown above.
Now I need to:
- Parse this time, exactly as it is, down to milliseconds precision
- Tick based on this time, so that I can do something precisely at some point in time, relative to it
I wanted to try new DateTime(year, month, day, hour, minute, second, millisecond)
, but I don't have the number of milliseconds (it's in the last parameter called msFormat
and I don't know it until I extract it, which is what I don't know).
I tried new DateTime(1970, 01, 01).AddMilliseconds(1590478340707)
which gives me a wrong time, because I know it's off even based on the remote server's time.
I also tried new System.Timers.Timer(1).Elapsed += HandleTimeBasedOnRemoteServerTime;
. But now I have no idea how to know the time of that server, because I can't use DateTime.Now
.
Could you please help?