0

I found how I log the time picked:

- (IBAction)save:(id)sender {

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"HH:mm"];
        NSLog(@"%@", [formatter stringFromDate:[datePicker date]]);
}

What I want to accomplish is:

I have a model class which is a sub-class of NSManagedObject, this is a class I created from my .model entity.

whenever I click "save" method I want to give the model class the count down time, so each object of this class will have it's countdown time and I can fire it up for each object...

i'm a beginner so it will be helpful if you can give me some guidance in what type of object should I store the count down time selected, and this is why I though putting it inside an integer but from what I see it's not true.

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
nick shmick
  • 905
  • 1
  • 9
  • 25
  • What number are you trying to get? The date can be stored in a model class directly as an NSDate or an NSTimeInterval since a reference date. Why are you trying to assign a date to an integer? – shim Dec 05 '14 at 20:16
  • date and integer? what is the relation? – Fahim Parkar Dec 05 '14 at 20:38
  • 2
    You said you want to put countDownDuration into an int, but then you show sampleCode where you access datePicker.date. Why don't you access datePicker.countDownDuration? That's a NSTimeInterval, you can quite easily cast it to NSInteger. – Matthias Bauch Dec 05 '14 at 20:41
  • hi shim, i added to the question what I want to accomplish so you can give me better tips..thanks!! @shim – nick shmick Dec 05 '14 at 20:51
  • hi buddy, i added more info to the question to make it more clear..would love to get your help @MatthiasBauch – nick shmick Dec 05 '14 at 20:52
  • @nickshmick What's wrong with simply doing `NSInteger duration = datePicker.countDownDuration;`? – rmaddy Dec 05 '14 at 21:37
  • Totally unclear what countdown you're talking about. – pronebird Dec 05 '14 at 23:22

1 Answers1

-1

You will need to extract the components of your NSDate. There's a class that does this: NSDateComponents.

Check out this other S.O. question for some guidance:

NSDate get year/month/day

Community
  • 1
  • 1
esreli
  • 4,993
  • 2
  • 26
  • 40