Tuesday, 31 January 2012

Convert_stringToDate,DateToString...


-(NSDate *)convertStringToDate:(NSString *) date {
        NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; 
        NSDate *nowDate = [[[NSDate alloc] init] autorelease];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];// set format here which format in string date
        date = [date stringByReplacingOccurrencesOfString:@"+0000" withString:@""];
        nowDate = [formatter dateFromString:date];
        // NSLog(@"date============================>>>>>>>>>>>>>>> : %@", nowDate);
        return nowDate;
}

    NSString *str = @"Tue, 24 May 2011 15:42:01 +0000";
    
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"];

    NSDate *date = [dateFormatter dateFromString: str];
    
    dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
    
    NSString *convertedString = [dateFormatter stringFromDate:date];
    NSLog(@"Converted String : %@",convertedString);




    NSLog(@"Date String Arrived =====>>>%@",strDate);
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy hh:mm:ss a"];
    NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
    NSLog(dateString); 


No comments:

Post a Comment