Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to convert from NSSTRING TO NSDATE ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 689
    Comment on it
    // date from string
    
    NSString *dateString = [NSString stringWithFormat:@"%@",_model.time]; // model.time is the field in which we are fetching the string.
       
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZ"];
        NSDate *dateFromString = [[NSDate alloc] init];
        dateFromString = [dateFormatter dateFromString:dateString];
       
    
      // string from date
    
    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
        [dateFormatter1 setDateFormat:@"dd-MMM-yyyy"];  // format in which we want our date to display
        NSString *stringOfDate = [dateFormatter1 stringFromDate:dateFromString];
        NSLog(@"%@", stringOfDate);


    Hello all !!
    Suppose we are fetching some data from the server through API Hit and in that we have one field having date and time both ( in string type) within it. Now what we want is to get only date from that string and not the time. So we have  to convert it from NSString to NSDate to get the desired result (we have to convert it again into NSString )..
    Then we can use this code to implement this !!

 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: