Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeZone Not Found Exception [duplicate]

I want to convert Indian DateTime object to Eastern DateTime object. Means I want to change time zone of particular DateTime object. For this I have written following code:

string easternZoneId = "Eastern Standard Time";
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById(easternZoneId);

string indianZoneId = "India Standard Time";
TimeZoneInfo indianZone = TimeZoneInfo.FindSystemTimeZoneById (indianZoneId);

DateTime d = TimeZoneInfo.ConvertTime (DateTime.Today, indianZone, easternZone);

When I try to run this statement I am getting, following exception in Console.

enter image description here

How to run this code? I want to convert my time into eastern time.

EDIT: Right now I am running my code in Unity Editor. I have iMac system. I want to run this code for iPhone devices.

like image 907
Siddharth Avatar asked Feb 16 '26 21:02

Siddharth


1 Answers

"India Standard Time" does not exist on my PC. You can list all the supported timezones on your PC (I have noticed that this can be different on other PC's) by listing them like this:

var timeZones = TimeZoneInfo.GetSystemTimeZones(); 
foreach (TimeZoneInfo timeZone in timeZones)
{
    Console.WriteLine(timeZone.Id);
}

Out:

  • Dateline Standard Time
  • UTC-11
  • Hawaiian Standard Time
  • ...
like image 199
Carra Avatar answered Feb 19 '26 11:02

Carra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!