I am planning to have an 'remind me on date' feature on my application. Hence I would want to receive the date from the user and store in SQLite.
开发者_开发技巧What is the easiest way to do this? Should i use the UIDatePicker
? If so, can you give me an hint of how to do it?
Is it simpler to use 3 picker views for year, month and date and store in SQLite?
Sorry if my question is a bit vague. I am new to iPhone development. I will be very thankful if someone can help me with this.
save date in string format.
Pick date from datePicker and conver into string and save it in db when you need this date you can again convert it into NSDate object.
see this
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/YYYY"];
NSString *dateString= [NSString stringWithFormat:@"%@",
[df stringFromDate:self.datePicker.date]];
save dateString in database.
For getting the date from the user, certainly use UIDatePicker.
For saving it, first consider using Core Data instead of sqlite directly. But if you insist, the easiest would probably be to convert the NSDate to a double using timeIntervalSinceReferenceDate
for storage, and use [NSDate dateWithTimeIntervalSinceReferenceDate:...]
to get back the NSDate when loading from the database.
精彩评论