我创建了一个日期选择器控制器,并希望将时间间隔设置为12小时实用。
但我不能这样做,我认为这是一个非常简单的问题,但请帮助我。
先感谢您。
试试这个:
NSDateFormatter *detailsTimeFormatter = [[NSDateFormatter alloc] init];
[detailsTimeFormatter setTimeStyle:NSDateFormatterShortStyle];
NSLog(@"%@",[[detailsTimeFormatter stringFromDate:[NSDate date]] lowercaseString]); // this will return you the time with am/pm
在Swift 4.X中:
let detailsTimeFormatter = DateFormatter()
detailsTimeFormatter.timeStyle = .short
detailsTimeFormatter.dateFormat = "HH:mm"
print(detailsTimeFormatter.string(from: Date()).lowercased())
将此时间字符串日期分配给选取器视图。