我的时间选择器出现问题,无法弄清楚我的问题是什么。这是我的代码;
timePicker.timeZone = [NSTimeZone localTimeZone];
NSDate *selected = [timePicker date];
NSString *message = [[NSString alloc] initWithFormat:
@"The date and time you selected is: %@", selected];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Date and Time Selected"
message:message
delegate:nil
cancelButtonTitle:@"Yes, I did."
otherButtonTitles:nil];
[alert show];
例如,如果我选择时间 2:55 pm,则警报将返回“2012-08-14 19:55:37 +0000”
它必须是非常简单的东西,只是看不到它
最佳答案
NSDate 没有时区的概念。它只存储中性时间信息。所以你必须纠正你的输出来补偿。
您可以创建 NSDateFormatter 的实例,然后 setTimeZone:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"..."];
//Timezone!
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]];
NSString *dateSting = [dateFormatter stringFromDate:myDate];
关于xcode timePicker 返回错误的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11959944/