Possible Duplicate:
Getting date from [NSDate date] off by a few hours
NSDate date don’t give me the right hour
I have this piece of code:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];
NSString *formattedDateInString = [formatter stringFromDate:[self.datePicker date]];
NSLog(@"This is the formatted date (STRING) ---> %@" ,formattedDateInString);
self.fromHourLabel.text = formattedDateInString;
NSDate *date = [formatter dateFromString:formattedDateInString];
NSLog(@"This is the date (NSDate) ---> %@" ,date);
self.fromHour = date;
I basically get the date from a UIDatePicker, set Hours and Minutes as a label text and save the date into a property called fromHour. In the -viewDidLoad
method I also have:
self.datePicker.timeZone = [NSTimeZone localTimeZone];
This is the output:
as you can see, with this code, I have two main problems:
- The first output say 17.30 and the second 16:30 (the first output is correct, the second is wrong) why?
- The second output is formatted with "yyyy-MM-dd HH:mm:ss" but I need only "HH:mm".
Can you help me?