Bug 37682 - Changing Time zone and time format(12 hrs to 24 hrs or viceversa) in iOS device not reflection in my application immediately
Summary: Changing Time zone and time format(12 hrs to 24 hrs or viceversa) in iOS devi...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.4
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-01-14 08:51 UTC by Nawnit Kumar
Modified: 2016-12-22 20:13 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Demo of solution (183.05 KB, application/x-zip-compressed)
2016-12-22 20:13 UTC, E.Z. Hart [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Nawnit Kumar 2016-01-14 08:51:27 UTC
In my app I need to change the time formate based on the time zone. I am changing the time zone in settings app of the iOS , my app is not changing time formate. I need to quit app and relaunch to see change and changing Hour time(24 to 12 hour formate) also not effecting even after relaunching app.

Below is the code I am using to in Xamarin.forms project

if (_completedDateTime != null) {
DateTime localTime = _completedDateTime.ToLocalTime ();

string[] dateTimeList = localTime.ToString ().Split (' ');
CompletedDateTimeString = "";

//below logic Adding ',' to separate date and time for showing UI
bool isCommaAdded = false;
for (int i = 0; i < dateTimeList.Count (); i++) {

if (i > 0 && !isCommaAdded) {

isCommaAdded = true;
CompletedDateTimeString += ", ";
CompletedDateTimeString += dateTimeList [i];
CompletedDateTimeString += " ";

} else {
CompletedDateTimeString += dateTimeList [i];

Comment 1 Paul DiPietro [MSFT] 2016-01-14 17:07:34 UTC
You will need to use data binding for this sort of thing. See here for a starter guide: https://developer.xamarin.com/guides/xamarin-forms/user-interface/xaml-basics/data_bindings_to_mvvm/
Comment 2 Nawnit Kumar 2016-01-21 06:09:00 UTC
Hi Paul,

Thanks for your reply. We have gone through the link you have provided, but it couldn't solve the problem for what we are trying to achieve. We are already aware of how to format the time based on 12-hr / 24-hr format string.

The actual problem that we are facing is to detect the changes done to the settings in iOS device.

Consider the scenario for your clear understanding.

1. Assume the application is in an open state and has a textfield which is bounded with current time with format 12-hr.

2. Now the user has gone to device settings and changed the time format from 12-hr to 24-hr format. 

3. User comes back to the application and checks the time format is updated as per  device settings.

4. In this case, I'm trying to format my textfield time format to respective format chosen by the user in the device settings. We were not able to detect the changes done for the device settings.

Can you please provide solution /  workaround how to proceed in this case.

Thanks in advance,
Nawnit Kumar
Comment 4 E.Z. Hart [MSFT] 2016-12-22 20:13:37 UTC
Created attachment 18975 [details]
Demo of solution
Comment 5 E.Z. Hart [MSFT] 2016-12-22 20:13:50 UTC
I'm afraid there's not a simple way to do what you're trying to accomplish.

The .NET DateTime methods will format the date and time according to the locale set on the device. For example, if the language/region is set to US English, it will use the 12-hour time format; UK English will use the 24-hour format. But the iOS system preference for 12 vs 24 hour clock format is independent of that setting. If you set the language/region to US English and then set the clock preference to 12-hour, the .NET DateTime methods will still look at the language/region setting and use the 12-hour default. 

If you want your application to respond to changes in that setting on iOS, one option would be to update the time value when your application resumes. You'll have to write iOS-specific code to detect the value of the setting, so you'll need to create a DependencyService in order to use that code from your XF application. 

I'm attaching a sample project which demonstrates how to do this.