How to get current Bahrain Date Time in Xamarin

Bhuwan 881 Reputation points
2022-06-01T08:21:52.687+00:00

Hi

How to get current Bahrain Date Time in Xamarin

i am using below code but getting error.

public static DateTime GetBahrainTime()
{
DateTime BHTime;
TimeZoneInfo UAETimeZone = TimeZoneInfo.FindSystemTimeZoneById("Arab Standard Time");
DateTime utc = DateTime.UtcNow;
BHTime = TimeZoneInfo.ConvertTimeFromUtc(utc, UAETimeZone);

        return BHTime;
    }
Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bhuwan 881 Reputation points
    2022-06-02T05:13:16.103+00:00

    Hi

    Working after using TimeZoneConverter Nuget package

    public static DateTime GetUtcByTimezone(string timezone)
    {
    DateTime dateTime;
    var timeZoneInfo = TZConvert.GetTimeZoneInfo(timezone);
    DateTime utc = DateTime.UtcNow;
    dateTime = TimeZoneInfo.ConvertTimeFromUtc(utc, timeZoneInfo);
    return dateTime;
    }
    DateTime dt=GetUtcByTimezone("Arab Standard Time");

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.