Hello,
Welcome to our Microsoft Q&A platform!
Please use Format
to control it. If you set it like following code format, the time is 24 hour format.
<TimePicker Format="HH:mm"></TimePicker>
=========================
Update===============================
You can use dependService to get the current system time settings if 12/24 hours format.
Create an interface called ITimer
.
public interface ITimer
{
bool IsTime12();
}
Then achieve it in android and iOS.
For Android.
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimePicker2412.Droid;
using Xamarin.Forms;
[assembly: Dependency(typeof(TimerService))]
namespace TimePicker2412.Droid
{
class TimerService : ITimer
{
public bool IsTime12()
{
//throw new NotImplementedException();
ContentResolver cv = Android.App.Application.Context.ContentResolver;
String strTimeFormat = Android.Provider.Settings.System.GetString(cv,
Android.Provider.Settings.System.Time1224);
if (strTimeFormat.Equals("24"))
{
return false;
}
else
{
return true;
}
}
}
}
For iOS.
using Foundation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimePicker2412.iOS;
using UIKit;
using Xamarin.Forms;
[assembly: Dependency(typeof(TimerService))]
namespace TimePicker2412.iOS
{
class TimerService : ITimer
{
public bool IsTime12()
{
var dateFormatter = new NSDateFormatter();
dateFormatter.DateStyle = NSDateFormatterStyle.None;
dateFormatter.TimeStyle = NSDateFormatterStyle.Short;
var dateString = dateFormatter.ToString(NSDate.Now);
var isTwelveHourFormat =
dateString.Contains(dateFormatter.AMSymbol) ||
dateString.Contains(dateFormatter.PMSymbol);
return isTwelveHourFormat;
}
}
}
When we use TimePicker
, we can judge the current system settings. If the system setting is 24 hours. We can set TimePicker.Format
in the background code.
if (!DependencyService.Get<ITimer>().IsTime12()) {
MyTimePicker.Format = "HH:mm";
};
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.