Im working on an app in which i want to fire local-notification on time set by user im just facing problem in getting correct time , So what im doing is this:
NSDateFormatter *current = [[NSDateFormatter alloc] init];
[current setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[current setDateFormat:@"HH:MM:SS"];
NSDate *systemTime = [NSDate date];
[current setTimeZone:[NSTimeZone systemTimeZone]];
NSLog(@"Current time %@" ,[current stringFromDate:systemTime]);
temp = [timeSetter date];//this temp is NSDATE object
NSLog(@"USer time %@" ,[current stringFromDate:temp]);
value = [temp timeIntervalSinceDate:systemTime];//This value is Nstimeinterval instance/obj.
And when im printing this through NSLog these are the results which i’ve recieved
I just ran your code, and reproduced a similar result. Your problem is with the
-setDateFormat:method – it should be[current setDateFormat:@"HH:mm:ss"]– this works OK for me.In date format strings M = month (02 = February), m = minute, S = fractions of a second and s = seconds.
If you look at the Apple documentation on date formatting, you’ll see that the format strings are determined in a Unicode standard. They link to various versions; the most recent is here