Friday, 14 June 2013

NSDateFormatter. NSString from NSDate. Convert date to string in iOS.


+(NSString*)convertDateToString:(NSDate *)date;

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];

    NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
    [timeFormat setDateFormat:@"HH:mm:ss"];


    NSString *theDate = [dateFormat stringFromDate:date];
    NSString *theTime = [timeFormat stringFromDate:date];
    return theDate;


}

No comments:

Post a Comment