in Education by
What is the best way to get timestamps in iOS and then calculate time on e.g. 2 timestamps? What data type is it? and if it is NSTimeInterval, can this value be stored in a dictionary that is then written to a plist? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Unix time is best. Indeed, using NSTimeInterval makes it really easy to calculate dates. It's just a double, so: NSDate *startDate; NSDate *endDate; NSTimeInterval interval; // assuming start and end dates have a value interval = [endDate timeIntervalSince1970] - [startDate timeIntervalSince1970]; When the dictionary is to be serialised or written to a document database like Couch or Mongo, I usually record the time interval as a NSString: NSDate *dateToStore; // assume dateToStore has a value NSTimeInterval aTimeInterval = [dateToStore timeIntervalSince1970]; NSString *aStringObject = [NSString stringwithFormat:@"%f", aTimeInterval]; NSDictionary *aDict = [NSDictionary dictionaryWithObject:dateAsString forKey:@"aKey"]; Then you can just read it back again when you use the dictionary object: NSTimeInterval newTimeInterval = [[aDict valueForKey:"aKey"] doubleValue]; NSDate *retreivedDate = [NSDate dateWithTimeIntervalSince1970:newTimeInterval]; If it's going to plist, you can just skip the string conversion.

Related questions

0 votes
    I have a UITextField inside of a UITableView cell. When I rotate the device, the textfield is still the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    what is the name of the mission which takes precise measurements of the diffuse radiation between 1 micrometer and 1 cm over the ... 1. COBE 2. Explorer 66 3. Verizon 4. 20322...
asked May 12, 2021 in General by JackTerrance
0 votes
    Which of the following approaches to testing is most appropriate when the results are expected to be precise? Many at a time One at a time...
asked Oct 25, 2020 in Technology by JackTerrance
0 votes
    R suffers from the disadvantage of being restricted to the local memory. Could you elaborate the precise memory limit in R?...
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
0 votes
    This is confusing, all I want is the Time from DateTime ? here is my code: clsdbo_RR.DateRecd = ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This is confusing, all I want is the Time from DateTime ? here is my code: clsdbo_RR.DateRecd = ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to implement the Hateoas using spring boot. In my UserController class i have used the below ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Two dice are thrown at the same time. Find the probability of getting (i) same number on both dice. (ii) different number on both dice. Select the correct answer from above options...
asked Nov 21, 2021 in Education by JackTerrance
0 votes
    Two dice are thrown at the same time. Find the probability of getting (i) Same number on both dice. (ii) different number of both dice. Select the correct answer from above options...
asked Nov 17, 2021 in Education by JackTerrance
0 votes
    A die is rolled thrice, find the probability of getting a larger number each time than the previous number. A. 5 ... D. none of these Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    Four cards are drawn at a time from a pack of 52 playing cards. Find the probability of getting all the four cards of the same suit. Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    What is the code for getting the current time? (a) now = new Date(); (b) var now = new ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
...