NSDate的处理

日期处理

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

[dateFormatter setTimeStyle:NSDateFormatterShortStyle];

//[dateFormatter setDateFormat:@"hh:mm:ss"]

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];

NSLog(@"Date%@", [dateFormatter stringFromDate:[NSDate date]]);

[dateFormatter release];

 

从nsstring转换为nsdate

+(NSDate *)NSStringDateToNSDate:(NSString *)string {

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

//#define kDEFAULT_DATE_TIME_FORMAT (@"yyyy-MM-dd'T'HH:mm:ss'Z'")

[formatter setDateFormat:kDEFAULT_DATE_TIME_FORMAT];

NSDate *date = [formatter dateFromString:string];

[formatter release];

return date;

}

你可能感兴趣的:(NSDate)