tags:

views:

6691

answers:

5

Is there a method in C#(.Net) that returns the UTC(GMT) time zone??? (Not based on the system's time). Basically I want to get the correct UTC time even if my system time is not right

+1  A: 

This gets the UTC time based on the sytem time, regardless of system timezone.

DateTime.Now.ToUniversalTime()
ck
This depends on the system's time.
Jon Skeet
Misread the question. Answer edited as per.
ck
You don't deserve a negative vote, this is still a useful, related answer. +1
Ali Parr
@Ali, thanks :)
ck
+2  A: 

Not based on the system's time? You'd need to make a call to a network time service or something similar. You could write an NTP client, or just screenscrape World Clock ;)

I don't believe .NET has an NTP client built in, but there are quite a few available.

Jon Skeet
A: 

If I were to wager a guess for how to get a guaranteed accurate time, you'd have to find / write some NNTP class to get the time off of a time server.

If you search C# NTP on google you can find a few implementations, otherwise check the NTP protocol.

Sciolist
A: 

If your system time is not right, nothing that you get out of the DateTime class will help. Your system can sync the time with time servers though, so if that is turned on, the various DateTime UTC methods/properties will return the correct UTC time.

Rob Prouse
A: 

As already been told: scrape worldclock site

PoweRoy