Karthik
Karthik

Reputation: 2399

Get Current Date time of the server on which my website is hosted

Am working on a functionality that involves a few timing based tasks.I need to retrieve current EST time to continue with my functionality.I do not need the system time since it may be different for each users.Is it possible using javascript or c# to get Eastern Standard Time from another time server or get time from my hosted server so that i can convert it to Eastern Standard Time .

am currently using this line of code to get eastern standard time but this is not i wanted since it is based on system time.

 DateTime eastern = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Eastern Standard Time");

Upvotes: 0

Views: 2307

Answers (1)

Alexei Levenkov
Alexei Levenkov

Reputation: 100620

Your current code looks correct - it returns current time in EST time zone.

There are potentially 4 different values for "now" in your case and I think you have right one:

  • UTC "now" - now in UTC time zone. - the same value irrespective of location/locale/anything.
  • Time in server local time zone (i.e. PST) - depends on server configuration
  • Time in browser's user time zone (i.e. India's half-an-hour timezone) - varies per user.
  • Time in EST.- the same value irrespective of location/locale/anything.

It is safe to convert UTC to known time zone as you did.

If you are not satisfied with precision/correctness of time on particular machine you can obtain time from a server that supports Network Time Protocol, but synchroniztion of clocks between machines is non-trivial task, so think first if it what you need.

Upvotes: 1

Related Questions