I am using DateTime.Now
to show something according to today's date, and when working locally (Malta, Europe) the times appear correctly (obviously because of the Time Zone) but ofcourse when I upload it to my hosting server (USA), DateTime.Now
does not represent the correct time zone.
Therefore, in my code, how can I convert DateTime.Now
to correctly return the time from a GMT + 1 timezone ?
Use the TimeZoneInfo class found in System.Core;
You must set the DateTimeKind to DateTimeKind.Utc for this.
DateTime MyTime = new DateTime(1990, 12, 02, 19, 31, 30, DateTimeKind.Utc);
DateTime MyTimeInWesternEurope = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(MyTime, "W. Europe Standard Time");
Only if you're using .Net 3.5 though!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With