Skip to main content

Objective C – datetime current

By July 24, 2012December 18th, 2013Blog

No more need to explain. How to get the current datetime and have it stored.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// get time and rotate minute arrow and hour arrow
// get current time
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 
// get the current hour & min
[dateFormatter setDateFormat:@"HHmm"];
NSDate *today = [NSDate date];
NSString *str = [dateFormatter stringFromDate:today];
NSString *strHour = [str substringToIndex:2];
NSString *strMin = [str substringFromIndex:2];
 
// convert hour and minute to the integer values so we can use it
NSInteger hour = [strHour integerValue];
NSInteger minute = [strMin integerValue];