0

I have a project that utilizes a web server as a GUI. I've added an expiration feature, essentially creating a desktop-like application that runs on a web server and is accessed through a browser. However, I'm experiencing issues with datetime.utcnow. Users can rollback the expiration by changing their system time. This method only calculates the local time and converts it to UTC. Is there a built-in class that can retrieve time from Microsoft? Windows has this feature and it can fix incorrect time zone issues by connecting to a Microsoft server.

Console.WriteLine(DateTime.UtcNow);
Dotnet
  • 11
  • 2
  • If you do any HTTP request to a web site, the headers include a `Date:` header that has the current time at that server. Pick any one you want. Of course, that requires an internet connection. – Tim Roberts Apr 23 '23 at 03:16
  • 1
    UTC isn't really the question here (that's a timezone thing) you want an external source of time such as an NTP server. Note that in theory a user could spoof that also. – Charlieface Apr 23 '23 at 03:19
  • @Charlieface Sorry to ask this question out of context, but I followed your suggestion to query an NTP server and I'm not sure how to convert the byte array containing the timestamp field to a DateTime value. Can you please help me with this? Here's the code I'm currently using: [link](https://dotnetfiddle.net/I9BrQm) – Dotnet Apr 23 '23 at 12:26
  • The code in the top voted answer on that link seems to work for me https://dotnetfiddle.net/yhtfQg – Charlieface Apr 23 '23 at 12:34

0 Answers0