Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Convert Facebook Datetime format in iPhone

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 669
    Comment on it

    Convert date format - 2013-10-31T07:41:39+0000 to 2013-10-31 01:48:11 +0000

    NSString *dateString = [stringDate substringToIndex:19]; 
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone localTimeZone];
    formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
    NSDate *theDate = [formatter dateFromString:dateString];
    NSLog(@"%@",theDate);
    
    formatter.dateFormat = @"MMM dd h:mma";
    NSDateFormatter *df = [NSDateFormatter new];
    [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
    
    //Create the date assuming the given string is in GMT
    df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    NSDate *date = [df dateFromString:stringDate];
    
    //Create a date string in the local timezone
    df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:[NSTimeZone localTimeZone].secondsFromGMT];
    df.dateFormat = @"MMM dd h:mma";
    NSString *localDateString = [df stringFromDate:date];
    NSLog(@"date = %@", localDateString);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: