0

I have Xamarin PCL project and I added NuGet package "NodaTime".

Especially I want to get difference of windows server time and my device time. Bu I couldn't find anything about this.

Aybuke
  • 211
  • 2
  • 16

1 Answers1

1

Well Noda Time doesn't have any kind of server-based functionality - and even if it did, that would be likely to be NTP. Matt Johnson has a separate NodaTime.NetworkClock package, which is an IClock implementation for NTP.

Now, does your server act as an NTP server? If not, it's likely you'll need something else.

It's not clear what your server is actually doing, but if you're able to add a "get current time" API, that could help... but you'd need to do a lot of work if you wanted to try to account for network latency. It would be fine for checking whether your device was minutes / hours out, of course.

All of this is assuming that what you're interested in is knowing whether the system clock itself is skewed. If you're just interested in the time zone offset from UTC, that's a different matter - ideally, you'd just find out the time zone of your Windows Server as well. Admittedly detecting the local time zone can be somewhat unreliable - Xamarin used to have issues with TimeZoneInfo.Local, where those issues depended on device platform, but it's possible the situation is better now.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I tried adding NodaTime.NetworkClock form NuGet but I have an error. I want to include in Portable Project but when I add from NuGet I'm getting this error; You are trying to install this package into a project that targets '.NetPortable,Version?v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. How can I add this package? – Aybuke Sep 06 '16 at 06:23
  • @Aybuke: Well it sounds like `NodaTime.NetworkClock` just doesn't support the PCL profile you need, unfortunately. But are you sure it's what you want in the first place? Are you sure your server exposes NTP? – Jon Skeet Sep 06 '16 at 06:29
  • Yes but I'm doing this without nuGet Library now. I'm using a method to get NTP from windows server. I saw that NuGet Library is not necessary to get NTP time from server. I'm using only one method now. – Aybuke Sep 07 '16 at 08:47
  • @Aybuke: Right, the package just makes it easier to integrate with Noda Time. So do you have any other questions at this point? – Jon Skeet Sep 09 '16 at 10:06
  • Thank you very much for your interest. I don't have any question for now – Aybuke Sep 09 '16 at 13:16