0

How do I get the original date and time from the system? I want to assign a specific date and time for users to login on the website. I know that I could get the date and time by using the DateTime.Now method, but every time I try to change the time and date of my laptop, it also changes. Is it possible to get the original date and time? If yes, please give me ideas on how to do it.

Briana
  • 87
  • 3
  • 9
  • What you mean by `Original`? store the earlier datetime somewhere for reusing – Rahul Sep 10 '16 at 14:07
  • You could query a NTP (Network Time Protocol) server. Check out this post http://stackoverflow.com/questions/1193955/how-to-query-an-ntp-server-using-c – Daniel Sep 10 '16 at 14:09

3 Answers3

0

You could get the date from the internet by making a simple web request and then checking the headers:

var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
var response = myHttpWebRequest.GetResponse();
var todaysDates = response.Headers["date"];

You may then want to parse todaysDate into a DateTime object.

Bassie
  • 9,529
  • 8
  • 68
  • 159
0

your website is hosted or not? if hosted than there is no problem in datatime. you can use

Datetime.UtcNow();
0

If by original you mean the local GMT date and time of login regardless of user's computer's date and time, you could use the date and time from the server.

Freddy Hdz
  • 137
  • 6