Bug 35337 - DateTime ToShortTimeString incorrectly formatted
Summary: DateTime ToShortTimeString incorrectly formatted
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 9.0 (iOS9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-10-28 15:26 UTC by Robert Sayers
Modified: 2016-04-12 15:26 UTC (History)
5 users (show)

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

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 Robert Sayers 2015-10-28 15:26:16 UTC
I think i may have discovered a bug relating to the ToShortTimeString() method on the DateTime Object in iOS where the string returned is not correctly formatted.  

If the culture settings for the device are set to United Kingdom and the 24hr setting in DateTime is set to Yes,  the string returned is in 24hr format (for example 23:00).  However if the 24hr setting under DateTime is set to no/off then this method still returns 23:00, surely it should be 11:00 p.m.  

Upon analysis if you use the NSDateFormatter class to format the string to ShortTime it will obey all the settings and return 11:00 pm if the 24hr setting is switched off and 23:00 if its switched on.  

Below is the sample piece of coding that i have used to illustrate this:

DateTime date = DateTime.Now;
toShortTimeStringLabel.Text = date.ToShortTimeString ();

NSDateFormatter formatter = new NSDateFormatter();
formatter.Locale = NSLocale.CurrentLocale;
formatter.DateStyle = NSDateFormatterStyle.None;
formatter.TimeStyle = NSDateFormatterStyle.Short;
NSDate nsDate = DateTimeToNSDate (date);

NSDateFormatLabel.Text = formatter.ToString(nsDate);

Any help on this would be greatly appreciated. 

System info:

Xamarin Studio
Version 5.9.7 (build 9)

Version: (Business Edition)

Apple Developer Tools
Xcode 6.4 (7720)

Many Thanks

Comment 1 Marek Safar 2015-10-29 13:21:35 UTC
DateTime::ToShortTimeString uses current culture formatting as recognized by .net. Whole culture properties are readonly by XI so any user changes won't affect ToShortTimeString output.

You need to use iOS specific formatter to have device specific behaviour.
Comment 2 Mohit Kheterpal 2016-01-11 15:04:21 UTC
If possible, could you please check the suggestion given in comment 1?

Comment 3 Robert Sayers 2016-01-11 16:23:03 UTC
Yeah I should be able to test it for at the latest Monday.  Is that ok?
Comment 4 Sebastien Pouliot 2016-04-12 15:26:49 UTC
We have not received further information and will assume this is not an issue anymore. If you can still affected by this please re-open the bug and include the requested information. Thanks.