I'm looking for an easy way to parse a string that contains an ISO-8601 duration in Objective C. The result should be something usable like a NSTimeInterval.
An example of an ISO-8601 duration: P1DT13H24M17S, which means 1 day, 13 hours, 24 minutes and 17 seconds.
...
I have a time interval that spans years and I want all the time components from year down to seconds.
My first thought is to integer divide the time interval by seconds in a year, subtract that from a running total of seconds, divide that by seconds in a month, subtract that from the running total and so on.
That just seems convoluted ...
I have 2 arrays with time values in it. They are in the following format. mm:ss:hundreds of a sec. I want to get the difference between the two [lastObjects] in the arrays. NSDate is not working because the last value is in hundredsth of a sec.
A question. If the second date is larger than the first will it give me a negative numb...
I have the following code:
NSDate *dateNow = [[NSDate alloc] init];
NSTimeInterval timeDifference = [usersDate timeIntervalSinceDate:dateNow];
// Get the system calendar
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
// Create the NSDates
NSDate *date1 = [[NSDate alloc] init];
NSDate *date2 = [[NSDate alloc] initWithTimeInterv...
I am communicating with a webservice to retrieve a numerical value that comes into my function as an NSString. This number tells me the precise amount of time to wait until I perform another action, and it is critical that it be precise.
As an example, if the string is "89283", then this means I must wait 89.283 seconds. So I'd like...
How would I set this method to display the alert panel 30 days from the initial launch of the application?
-(void)awakeFromNib
{
NSDate * today = [NSDate date];
NSTimeInterval expiry = ();
if ([today timeIntervalSinceReferenceDate] > expiry){
NSRunAlertPanel(@"Trial period has ended", @"Please Register", nil, nil, nil);
NSLog(@"e...
There's two ways of storing an NSDate in NSUserDefaults that I've come across.
Option 1 - setObject:forKey:
// Set
NSDate *myDate = [NSDate date];
[[NSUserDefaults sharedUserDefaults] setObject:myDate forKey:@"myDateKey"];
// Get
NSDate *myDate = (NSDate *)[[NSUserDefaults sharedUserDefaults] objectForKey:@"myDateKey"];
Option 2 - t...
Hi everyone
I have a weird memory leak with NSTimeIntervall and NSDate. Here is my code:
NSTimeInterval interval = 60*60*[[[Config alloc] getCacheLifetime] integerValue];
NSDate *maxCacheAge = [[NSDate alloc] initWithTimeIntervalSinceNow:-interval];
if ([date compare:maxCacheAge] == NSOrderedDescending) {
return YES;
} else {
...
I know the quick and dirty way of dividing by 60 to get minute, hours, etc
But is there an official way in the API already implemented, and using the appropriate language for minutes, seconds, etc?
Thanks for any help.
...
Hi everyone,
I try to get the last modification date of a file:
NSFileManager *fm = [[NSFileManager alloc] init];
NSError *err;
NSDate *lastModif = [[fm attributesOfItemAtPath:filename error:&err] objectForKey:NSFileModificationDate];//filename is ok ;-)
if(err == nil) {
[lastModif retain];
//I can put a NSLog of lastModif here...
Hi all,
Is there any way how can i convert a nstimeinterval type value to a string type in xcode?
Thanks in advance
Joy
...
Hi,
I am doing my program in cocos2d.
I am using NSDate to get the current time of the start of animation. And I know my animation takes 3 seconds. So I can get the time at completion of animation by using NSInterval and using the previous time and animation time. But, if If the animation time interval is not fixed how can I calculate t...
I have the following code:
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerCount:) userInfo:nil repeats:YES];
-(void)timerCount:(NSTimer *)timer
{
NSTimeInterval dt = [timer timeInterval];
// do something
}
The NSTimeInterval I got will be 0.5, the time interval I've put on scheduledTimerWithI...
In my ViewController I am using UIButton which triggers some action when touchedUpInside. Upto here no problem, but i also want to add another action for touchDown event. More precisely i dont have an idea how to add that action to which event, that will work the same as when App-Icon is pressed longer in springboard which causes springb...
Although I'm coding in Objective C, this is more of a general programming question.
What is the best way to convert a constantly changing scalar value to a changing interval or frequency?
Right now every time the scalar value changes I am destroying the NSInterval
ie
[self.myTimer invalidate];
self.myTimer = nil;
and creating...
I'm still new to Objective C syntax, so I might be overcomplicating this, but I can't seem to figure out how to pass an NSTimeInterval to a thread.
I want to initiate a thread that sleeps for x seconds parameter sent from main thread as follows:
[NSThread detachNewThreadSelector:@selector(StartServerSynchThread) toTarget:self withObje...
how to convert NSInteger to NSTimeInterval?
...
Hello,
Please do tel me how to convert int to NSTimeInterval?
Thank You.
...
Hello,
How do i encode and decode NSTimeInterval?
when i do it in this way...
NSTimeInterval refreshInterval;
[coder encodeObject:refreshInterval forKey:@"refreshinterval"];
it throws an error saying , incompatible type
How to solve this problem?
or the correspoinding thing is to convert NSTimeInterval to int and vice-verse.. but...
i want to produce the delay of 2 sec using nstimer how to initialise timer in program?....
...