如何在iphone中将NSTimeZone设置为日期选择器控制器

问题描述 投票:0回答:2

我创建了一个日期选择器控制器,并希望将时间间隔设置为12小时实用。

但我不能这样做,我认为这是一个非常简单的问题,但请帮助我。

先感谢您。

iphone objective-c nstimeinterval
2个回答
0
投票

试试这个:

NSDateFormatter *detailsTimeFormatter = [[NSDateFormatter alloc] init];
    [detailsTimeFormatter setTimeStyle:NSDateFormatterShortStyle];
    NSLog(@"%@",[[detailsTimeFormatter stringFromDate:[NSDate date]] lowercaseString]); // this will return you the time with am/pm

0
投票

在Swift 4.X中:

let detailsTimeFormatter = DateFormatter()
detailsTimeFormatter.timeStyle = .short
detailsTimeFormatter.dateFormat = "HH:mm"
print(detailsTimeFormatter.string(from: Date()).lowercased())

将此时间字符串日期分配给选取器视图。

© www.soinside.com 2019 - 2024. All rights reserved.