ios 将NSDate精确到天 (通用版本)

        NSDate *nowDate1 = [NSDatedate];

        NSDateFormatter *formatter = [[[NSDateFormatteralloc] init] autorelease];

        [formatter setDateFormat:(@"yyyy-MM-dd")];

     NSMutableString *dateStr = [NSMutableStringstringWithString: [formatter stringFromDate:nowDate1]];//[NSMutableString stringWithFormat: @"%@ 00:00:00 +0000"];

        NSLog(@"%@", dateStr);

        

        nowDate1 = [self NSStringDateToNSDate: dateStr];

        NSLog(@"%@",nowDate1);

        - (NSDate *)NSStringDateToNSDate:(NSString *)string 

{    

    NSDateFormatter *formatter = [[NSDateFormatteralloc] init];

    [formatter setTimeZone:[NSTimeZonetimeZoneWithAbbreviation:@"UTC"]];

    #define kDEFAULT_DATE_TIME_FORMAT (@"yyyy-MM-dd")

    [formatter setDateFormat:kDEFAULT_DATE_TIME_FORMAT];

    NSDate *date = [formatter dateFromString:string];

    [formatter release];

    return date;

}

你可能感兴趣的:(ios,Date,String)