gpt4 book ai didi

iphone - 显示上一个日期的 DatePicker

转载 作者:行者123 更新时间:2023-11-28 23:03:58 26 4
gpt4 key购买 nike

-(IBAction)pickerChanged:(id)sender
{
UIDatePicker *picker = (UIDatePicker *)sender;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
//NSDate *dateSelected is declared in .h file
self.dateSelected = [picker date];
if(self.textField.tag == 101)
self.textField.text = [dateFormatter stringFromDate:self.dateSelected];

nslog(@"date = %@",self.textField.text);
nslog(@"dateSelected = %@",self.dateSelected);
}

textfield.text 和 date selected 应该相同但是,在输出日志中....如果我得到 date = 2-1-2012 我得到 datestelected = 1-1-2012...并且日期是保存为 1-1-2012。我无法找出问题所在。

最佳答案

这可能是因为时区不同。添加这个,它对我有用:

 [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

关于iphone - 显示上一个日期的 DatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9584508/

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