My machine is on PDT and if I say DateTime.Now, then I will get a local time which is say equivalent to Sep-18th 2012 6:00:00 AM. I want to get UTC equivalent for this datetime instance. UTC time will be 7 hours ahead Of PDT and 8 hours ahead of PST. I want to consider daylight saving automatically.
Any idea on how I can do this?
You can use
To convert an existing DateTime, assuming it has time zone information, you can use DateTime.ToUniversalTime(). If you get the DateTime instance using e.g.
it will have time zone information. If you create it e.g. using a tick count, it will not contain timezone information unless you explicitly supply it.
It is worth mentioning that timezone handling in .NET is not optimal. You may wish to have a look at Noda Time (a project by Jon Skeet) if you need to do anything elaborate involving time zones.