vartz=TimeZoneInfo.ConvertTime(DateTime.Now,TimeZoneInfo.Local,TimeZoneInfo.FindSystemTimeZoneById("IndiaIndia Standard Time"));Console.WriteLine(tz);
Output
kodingwindow@kw:~/csharp$ dotnet run
Unhandled exception. System.TimeZoneNotFoundException: The time zone ID 'IndiaIndia Standard Time' was not found on the local computer.
---> System.TimeZoneNotFoundException: The time zone ID 'IndiaIndia Standard Time' is invalid.
--- End of inner exception stack trace ---
at System.TimeZoneInfo.FindSystemTimeZoneById(String id)
at Program.<Main>$(String[] args) in /home/kodingwindow/csharp/Program.cs:line 1
kodingwindow@kw:~/csharp$
C# program to handle the TimeZoneNotFoundException
Program.cs
try{varctz=TimeZoneInfo.ConvertTime(DateTime.Now,TimeZoneInfo.Local,TimeZoneInfo.FindSystemTimeZoneById("IndiaIndia Standard Time"));Console.WriteLine(ctz);}catch(TimeZoneNotFoundExceptione){Console.WriteLine(e.Message);Console.WriteLine("\nList of correct time zone IDs");vartz=TimeZoneInfo.GetSystemTimeZones();foreach(TimeZoneInfotziintz){Console.WriteLine(tzi.Id);}}
Output
kodingwindow@kw:~/csharp$ dotnet run
The time zone ID 'IndiaIndia Standard Time' was not found on the local computer.
List of correct time zone IDs
Dateline Standard Time
Hawaiian Standard Time
Marquesas Standard Time
Alaskan Standard Time
...
Pacific/Fakaofo
Pacific/Tongatapu
Pacific/Kiritimati
kodingwindow@kw:~/csharp$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the KodingWindow Android app. We intend to soon make it available on the Google Play Store. Currently, you need to install apk manually. Would you like to get the app? Minimum Requirement(s): Android 10