iOS. Расширение возможностей NSDate

@implementation NSDate (DateWork)

-(NSDateComponents *)getTime {
	NSCalendar *calendar = [NSCalendar currentCalendar];
	return [calendar components:(kCFCalendarUnitHour | kCFCalendarUnitMinute | kCFCalendarUnitSecond) fromDate:self];
}

-(int)getHours {
	return [[self getTime] hour];
}

-(int)getMinutes {
	return [[self getTime] minute];
}

-(int)getSeconds {
	return [[self getTime] second];
}

-(NSDate *)dateByAddingHours: (int)value {
	return [self dateByAddingTimeInterval:value * 3600];
}

-(NSDate *)dateByAddingMinutes: (int)value {
	return [self dateByAddingTimeInterval:value * 60];
}

-(NSDate *)dateByAddingSeconds: (int)value {
	return [self dateByAddingTimeInterval:value];
}

-(NSString *)toUniversalTime {
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
	[dateFormatter setDateStyle:NSDateFormatterShortStyle];
	NSString *str = [dateFormatter stringFromDate:self];
	[dateFormatter release];
	return str;
}

-(NSString *)toUniversalTimeWithRTag {
	NSDateFormatter *df = [[NSDateFormatter alloc] init];
	[df setDateFormat:@"EEE, d MMM yyyy HH:mm:ss 'GMT'"];
	NSString *str = [df stringFromDate:self];
	[df release];
	return str;
}

@end

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *