Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective C - create NSDate from two Strings
    primarykey
    data
    text
    <p>Short version: Is there a way to combine two <code>NSDates</code> (which can be formed from two different strings) into a single <code>NSDate</code> object?</p> <p>Detail: In my app, there are two textfields where the user enters the day and the time, respectively (these are entered using a customised Date Picker). When I want to save the information in the database, the property of the object expects a single date, comprised of both the day and the time.</p> <p>Here is how I set the strings:</p> <pre><code> if ([mode isEqualToString:@"date"]) { self.dateFormat = [[NSDateFormatter alloc] init]; [self.dateFormat setDateFormat:@"MM/dd/yy"]; self.dateTextField.text = [self.dateFormat stringFromDate:date]; } else if ([mode isEqualToString:@"time"]) { self.timeFormat = [[NSDateFormatter alloc] init]; [self.timeFormat setDateFormat:@"hh:mm a"]; self.timeTextField.text = [self.timeFormat stringFromDate:date]; } </code></pre> <p>where <code>date</code> is a <code>NSDate</code> passed in to the method. Now when I am trying to save the information in a different method, I have access to the strings and the date formats, so I am able to do</p> <pre><code>NSDate* tempDate = [self.dateFormat dateFromString: self.dateTextField.text]; NSDate* tempTime = [self.timeFormat dateFromString: self.timeTextField.text]; </code></pre> <p>but that's as far as I can get... I'm not sure how to combine the dates together into a single entity. Would I combine the DateFormatter strings together somehow?</p> <p>Thank you for your help :)</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.
 

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