我正在尝试在标签或文本字段中从 uipicker 显示所选时区的日期和时间我没有任何方法可以解决这个问题,所以请任何人帮助我提前致谢。
SelectedTimeZone= [权重 objectAtIndex:[pickerView selectedRowInComponent:0]]; NSString *selectedzone = SelectedTimeZone;
NSCalendar *gregorian=[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setTimeZone:[NSTimeZone timeZoneWithName:selectedzone]];
NSDateComponents *timeZoneComps=[[NSDateComponents alloc] init];
NSDate *date=[gregorian dateFromComponents:timeZoneComps];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterFullStyle];
[formatter setDateFormat:@"dd-MM-yyyy HH:mm:ss "];
NSString *todaysDate= [formatter stringFromDate:[NSDate date]];
zone.text = todaysDate; I know this is not proper way but i'm new to xcode