Reputation: 2399
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
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:
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