gpt4 book ai didi

ios - 我的日期选择器返回错误的分钟和秒值

转载 作者:行者123 更新时间:2023-11-29 04:01:39 26 4
gpt4 key购买 nike

我的日期选择器返回的分钟和秒值错误,但小时工作正常。这是我的获取方法。

-(NSDate *)datePickerTime
{
NSCalendar *gregorianCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
[gregorianCalendar setTimeZone:[NSTimeZone localTimeZone]];
NSDateFormatter *format = [[NSDateFormatter alloc]init];
[format setDateFormat:@"HH:mm:ss"];
[format setTimeZone:[NSTimeZone localTimeZone]];
NSString *dateString =[format stringFromDate:[self.timePicker date]];
NSDate *adjustedDate = [format dateFromString:dateString];
NSDateComponents *comp = [[NSDateComponents alloc]init];

comp = [gregorianCalendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:adjustedDate];

reminderTime = [gregorianCalendar dateFromComponents:comp];

return reminderTime;
}

最佳答案

请查看最佳Apple sample code日期选择器,支持所有类型的格式!

您的问题可能出现在 setDateFormat ISO-8601

试试这个代码

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:@"hh:mm:ss a"];

NSLog(@"Current Date: %@", [formatter stringFromDate:[NSDate date]]);

[formatter release];

关于ios - 我的日期选择器返回错误的分钟和秒值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15784981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com