Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i convert Convert DateTime.Now To GMT... I saw many posts in web to convert to UTC but not GMT
Posted

Use the TimeZoneInfo class found in System.Core;

You must set the DateTimeKindto DateTimeKind.Utc for this.

C#
DateTime MyTime = new DateTime(1990, 12, 02, 19, 31, 30, DateTimeKind.Utc);

DateTime MyTimeInWesternEurope = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(MyTime, "W. Europe Standard Time");


Please refer: Converting Times Between Time Zones[^]
also check similar discussion:C#: Making sure DateTime.Now returns a GMT[^]
 
Share this answer
 
Comments
Arjun Menon U.K 24-Jul-12 23:29pm    
UTC and GMT are different know?
UTC is GMT.
 
Share this answer
 
Comments
Mehdi Gholam 25-Jul-12 0:14am    
Yes they are the same, but the confusion occurs because of daylight savings which is country based and unfortunately for the UK conflicts.
Richard MacCutchan 25-Jul-12 4:18am    
I don't understand what you mean. UTC and GMT are the same and have nothing to do with daylight saving.
Arjun Menon U.K 25-Jul-12 8:00am    
Richard I think he meant by difference in a sense that both are different measures to calculate time...
Richard MacCutchan 25-Jul-12 8:36am    
No, they are not, they are exactly the same.
 
Share this answer
 
Comments
Arjun Menon U.K 24-Jul-12 23:29pm    
UTC and GMT are different know?
Mehdi Gholam 25-Jul-12 0:12am    
No they are the same, but the confusion occurs because of daylight savings which is country based and unfortunately for the UK conflicts.
Arjun Menon U.K 25-Jul-12 0:36am    
mmm Thanks anyways .... Mehdi .. cheers
Go through this page;-
World Clock and the TimeZoneInformation class[^]

Hope it will help you.
 
Share this answer
 
UTC takes care of standard time issues and thus that is used most of times and is present in most of the places.

In case you want to have for defined zone, what about trying something like:
C#
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");  
Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(date1, tz));     
 
Share this answer
 
Comments
Arjun Menon U.K 24-Jul-12 23:29pm    
UTC and GMT are different know?
Richard MacCutchan 25-Jul-12 4:21am    
No, see my comment, UTC and GMT are always the same, the standard universal time from which all local times are derived.
There's already a property for that, DateTime.UtcNow
 
Share this answer
 
Comments
Arjun Menon U.K 24-Jul-12 23:29pm    
UTC and GMT different na?
lewax00 24-Jul-12 23:32pm    
No, they're the same thing: http://en.wikipedia.org/wiki/Coordinated_Universal_Time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900