0
- (void)timeZoneChange
{

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    [dateFormatter setTimeZone:timeZone];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString = [dateFormatter stringFromDate:self.birthdate];

    NSDateFormatter* estDf = [[NSDateFormatter alloc] init];
    NSTimeZone *timeZone2 = [NSTimeZone systemTimeZone];
    [estDf setTimeZone:timeZone2];
    [estDf setDateFormat:@"yyyy-MM-dd"];
    self.timeZoneDate = [estDf dateFromString:dateString];

My problem : I take self.birthdate from user and I change to dateString in his TimeZone. I need to save changed date into CD as NSDate so I changing StringToDate with SystemTimeZone and self.timeZoneDate returns UTC date not in systemTimeZone.

Example self.birthdate = 27.04.2005 then self.timeZoneDate = 26.04.2005 22:00:00 +0000. I now [NSDate date] = UTC time but is any trick ? I need self.timeZoneDate as date in systemTimeZone

Amdx Rux
  • 95
  • 8
  • There is absolutely no reason you need to convert an `NSDate` to another `NSDate` to make any sort of timezone adjustment. Why do you think you need to do this? – rmaddy May 16 '16 at 17:44
  • Because I got NSDate and i dont know how to change NSDate timezone without change first to string. – Amdx Rux May 16 '16 at 17:45
  • 1
    `NSDate` **does not have a time zone**, so there is no way to change its time zone. – Tom Harrington May 16 '16 at 17:46
  • @AmdxRux I asked why you think you need to change the date's timezone. What is your goal? The only time a timezone is relevant is when you need to create a string from the date to display it to the user. – rmaddy May 16 '16 at 17:49
  • So i got NSDate from DatePicker. I want to adjust this date to user device date and save to DB. I dont want situation when user birthday's are example 2.02.2016 but in DB will be 1.02:2016 22:00:00 – Amdx Rux May 16 '16 at 17:50
  • NSDate represents an instant in time on planet Earth. It does not have a time zone. When a user inputs a date into a date picker, he will express that date in his local time zone, but when you ask the picker for the date that the user selected, it will give it back to you as an `NSDate` that is not specific to a time zone. If you then use a date formatter to display that date, it will be displayed in the time zone of the date output date formatter – Duncan C May 16 '16 at 18:16

0 Answers0