Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>timeInterval</code> is the amount of time in seconds, so if you want it in hours and fractions of an hour just do this:</p> <pre><code>double timeIntervalInHours = timeInterval / 3600.0; </code></pre> <p>and then multiple <code>timeIntervalInHours</code> times the price/hour to get the cost.</p> <p><strong>EDIT</strong><br> Based on our chat, I would create a button with "iniciar" (start) as the title. When they press that button, I would store the current time and change the title to "encerrar" (stop). (I hope that my translations are correct, lol) Then the button action would look something like this:</p> <pre><code>// self.startTime is a NSDate. - (IBAction)iniciar_encerrar:(UIButton *)sender { if ([sender.titleLabel.text isEqualToString:@"iniciar"]) { // We are starting the time if (self.startTime != nil) { return; } self.startTime = [NSDate date]; [sender setTitle:@"encerrar" forState:UIControlStateNormal]; } else { // We are stopping the time NSDate *currentTime = [NSDate date]; NSTimeInterval elapsedTimeInSeconds = [currentTime timeIntervalSinceDate:self.startTime]; double cost = elapsedTimeInSeconds / 3600.0 * 5.0; NSLog(@"%.2lf", cost); // reset the button self.startTime = nil; [sender setTitle:@"iniciar" forState:UIControlStateNormal]; } } </code></pre> <p><strong>startTime is declared as follows:</strong> </p> <p>In your .h file, along with the other declared properties, add:</p> <pre><code>@property (strong, nonatomic) NSDate *startTime; </code></pre> <p>In your .m file, add this at the top with the other ones:</p> <pre><code>@synthesize startTime; </code></pre> <p>In your <code>viewDidUnload</code> function (in your .m file) add this:</p> <pre><code>startTime = nil; </code></pre> <p>This just gives you a place to store the startTime date.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload