how to calculate the other country time. using my local machine time in c#?
Example:
My system having India time and my array contains all the countries GMT time.
How to do the calculation to get the other country time?
if my time is 5.00 P.M if the country is Pakistan it should show 4.30 p.m
Assuming you’re using .NET 3.5 or higher, you need to get the right
TimeZoneInfo(e.g. by ID). From then on, it’s fairly simple – I’d suggest that you use UTC wherever it’s available, and probablyDateTimeOffsetrather thanDateTimeas that’s less ambiguous. Take your current time withDateTimeOffset.UtcNow, get the appropriate time zone to convert to, and then useTimeZoneInfo.ConvertTime(DateTimeOffset, TimeZoneInfo). That will get you the appropriate newDateTimeOffset(i.e. offset by the appropriate amount in the target time zone) which you can then format appropriately.