-
Notifications
You must be signed in to change notification settings - Fork 4
/
NSDate-Extras.m
46 lines (37 loc) · 1.06 KB
/
NSDate-Extras.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// NSDate-Extras.m
// LastHistory
//
// Created by Frederik Seiffert on 13.12.09.
// Copyright 2009 Frederik Seiffert. All rights reserved.
//
#import "NSDate-Extras.h"
@implementation NSDate (Extras)
- (NSDate *)day
{
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
fromDate:self];
return [calendar dateFromComponents:comps];
}
- (NSInteger)year
{
NSDateComponents *comps = [[NSCalendar currentCalendar] components:NSYearCalendarUnit fromDate:self];
return [comps year];
}
- (NSInteger)month
{
NSDateComponents *comps = [[NSCalendar currentCalendar] components:NSMonthCalendarUnit fromDate:self];
return [comps month];
}
- (NSInteger)hour
{
NSDateComponents *comps = [[NSCalendar currentCalendar] components:NSHourCalendarUnit fromDate:self];
return [comps hour];
}
- (NSInteger)weekday
{
NSDateComponents *comps = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:self];
return [comps weekday];
}
@end