I have a bunch of date times that I keep track of for my app. They are all in UTC time. For part of my app I want to send an email with one of these times, but edited to be
var now = DateTime.Now; // Current date/time
var utcNow = now.ToUniversalTime(); // Converted utc time
var otherTimezone = TimeZoneInfo.FindSystemTimeZoneById("ANY OTHER VALID TIMEZONE"); // Get other timezone
var newTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, otherTimezone); // New Timezone
This should do the trick
DateTime localTime = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.Local);
You can use javascript:
var visitortime = new Date();
vat time = visitortime.getTimezoneOffset()/60;
After that you can save this value to any hidden control which is runat ="server".
Use TimeZoneInfo.ConvertTimeFromUtc. The example listed there is pretty self explanatory.
why not just
TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "AUS Eastern Standard Time");
and check get all available timezones
foreach (TimeZoneInfo tz in TimeZoneInfo.GetSystemTimeZones())
{
Console.WriteLine(tz.Id);
}
Use the TimeZoneInfo Class to convert a local time to a time in an alternative timezone:
TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime targetTime = TimeZoneInfo.ConvertTime(timeToConvert, est);