我在项目中使用日期选择器,并且在将格式属性应用为hh:mm后,我将选择日期设置为24小时格式。我可以通过使用条件转换它来获得12小时格式日期,但我想知道一些直接的方法从日期选择器获得12小时格式时间与AM,PM。如果有人知道最短的方式,请通过你的回答表明我。 谢谢!
答案 0 :(得分:5)
我为此做了一个方法,试试吧
-(NSString*)getTimetoFill
{
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"h:mm a"];
NSString *timetofill = [outputFormatter stringFromDate:datepicker.date];
return timetofill;
}