All your code needs to do is this:
string tzid = SelectedCountry == Australia
? "AUS Eastern Standard Time"
: "India Standard Time";
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(tzid);
DateTime appTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);
Of course, you are making a serious mistake in thinking that all of Australia is on a single time zone. See this Wikipedia article for details.
What's likely the reason that your code didn't work when you sent it to production is that you were relying on DateTime.Now
to be India. There's a good chance that your server is in another time zone. For example, it's a best practice to put servers in UTC.
Besides, it's a bit silly to think that your users will only be in one of two different time zones. You should probably just create a list via TimeZoneInfo.GetSystemTimeZones()
, using the .Id
and .DisplayName
of each item.
You might also want to make sure that your servers have the latest Windows Updates, or you have applied the Time Zone Updates manually.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…