Sunny
Sunny

Reputation: 1534

Convert UTC DateTime to specific time zone xamarin forms pcl

I am working on a project in which i am getting UTC DateTime in service response. I am trying to convert UTC DateTime to Datetime in specific time zone. i have tried System.TimeZoneInfo.ConvertTimeBySystemTimeZoneId but it is unavailable in xamarin forms pcl.

Is there any solution or workaround to handle this scenario?

Thanks

Upvotes: 9

Views: 6235

Answers (2)

Diego Rafael Souza
Diego Rafael Souza

Reputation: 5314

Try to use ToLocalDateTime() this way:

DateTime date = DateTime.Now;
var test = date.ToLocalDateTime();

Upvotes: 3

Ziyad Godil
Ziyad Godil

Reputation: 2680

Try below code:

TimeZoneInfo.ConvertTime(date, TimeZoneInfo.Local);

Upvotes: 2

Related Questions