Re: Finding the offset of a specific time zone
Peter Ritchie <[email protected]> Wed, 25 Mar 2009 12:43:55 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
You can use DateTime.UtcNow to get the current time in UTC. e.g.: DateTime utcDate = DateTime.UtcNow; You can use DateTime.ToUniversalTime() to convert a local time to UTC. e.g.: DateTime date = new DateTime(1968, 11, 05, 12,0,0); DateTime utcDate = date.ToUniversalTime(); You can change the type of a date from local to UTC with the SpecifyKind method (i.e. you get a DateTime object from a database; but it's default kind is local and its value is actually UTC) e.g: DateTime dateTime = GetRecordDateFromDatabase(id); dateTime = dateTime.SpecifyKind(DateTimeKind.Utc); You can convert a UTC time to local time with DateTime.ToLocalTime. E.g.: DateTime utcDate = GetUtcDateFromSomewhere(); DateTime localDate = utcDate .ToLocalTime(); -- Peter =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives