Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UIDatePicker中禁用24小时格式_Ios_Iphone - Fatal编程技术网

Ios 如何在UIDatePicker中禁用24小时格式

Ios 如何在UIDatePicker中禁用24小时格式,ios,iphone,Ios,Iphone,我想禁用UIDatePicker中的24时钟格式,我的要求是只显示AM/PM格式的日期选择器。如果用户在手机设置中启用24小时。我的日期选择器显示24小时格式,我想强制它显示12小时格式。请推荐我 谢谢,您无法设置12/24格式 这取决于用户在其iOS设备上的设置。如果用户按照iOS设备设置设置方式,则我们只能自定义当前日期为24小时格式。。否则我们可以这样设置 NSDate *currDate = [NSDate date]; NSDateFormatter *dateFormatter =

我想禁用UIDatePicker中的24时钟格式,我的要求是只显示AM/PM格式的日期选择器。如果用户在手机设置中启用24小时。我的日期选择器显示24小时格式,我想强制它显示12小时格式。请推荐我


谢谢,

您无法设置12/24格式


这取决于用户在其iOS设备上的设置。

如果用户按照iOS设备设置设置方式,则我们只能自定义当前日期为24小时格式。。否则我们可以这样设置

NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

NSString *dateString = [dateFormatter stringFromDate:currDate];

_todayDateLbl.text=dateString;
#pragma get current time

dateFormatter.dateFormat = @"hh:mm a";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSLog(@"The Current Time is %@",[dateFormatter stringFromDate:currDate]);

日期格式取决于您的设备区域设置

尽管在大多数情况下不建议这样做,但您可以覆盖区域设置:

例如,这将为您提供24小时格式:

self.datePicker.locale=[NSLocale localewithlocaleignifier:@“en_GB”]

这是12小时制,下午/上午


self.datePicker.locale=[NSLocale localewithlocaleignifier:@“en_US”]

取决于区域设置,但您可以构建自己的日期选择器。

对于24小时格式,请尝试

 NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"NL"];
 [self.datePicker setLocale:locale];

你的意思是我们不能自定义日期选择器。不,我们不能。UIDatePicker与系统配置相关。苹果必须这样做,以确保用户的安全experience@nikey您可以将[NSLocale localeWithLocaleIdentifier:@“en_GB”]设置为24小时格式,也可以使用AM/PM选项将[NSLocale localeWithLocaleIdentifier:@“en_US”]设置为12小时格式。如果可以将日期选择器设置为计时器模式,则默认格式为12小时AM/PM格式。谢谢,她想禁用它,而不是启用它。