0

I am not too familiar with date time. I am currently wonder how can I convert the existing time of the device to a different countries' date/time.

E.g. App.CurrentDate <- which display the device setting date/time. I want it to be in different country's time when choosing different site where the site can be any countries

Is it possible to achieve this?

LittleFunny
  • 7,771
  • 14
  • 78
  • 184

2 Answers2

1

Android and iOS use IANA timezone names. They look like this “America/New_York” and you can find a list of them at the List of tz database time zones.

TimeZoneInfo estZone = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
DateTime estTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, estZone);

References:

1 http://www.xamarinhelp.com/time-zones-xamarin-forms/

2 https://help.syncfusion.com/xamarin/scheduler/timezone

Divyesh_08
  • 1,563
  • 15
  • 25
-2

Grab the current date and time in UTC format first

var utcTime = DateTime.UtcNow;

Then convert it to whichever timezone you need

TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
DateTime zoneTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, zone);

Here is how to get a list of all the time zones

More details about UTC

It's also possible to identify the timezone based on co-ordinates - this answer shows how

Steve Chadbourne
  • 6,683
  • 3
  • 54
  • 81