【发布时间】:2017-10-27 18:49:54
【问题描述】:
我想要像 hh:mm:ss (10:45:32) 而不是像 2017-10-24 10:45:32 +0600,如何在 Core Data 中实现?
- (IBAction)SaveTasks:(UIButton *)sender
{
[dateformater setDateFormat:@"dd/MM/yyyy"];
NSDate *date = [dateformater dateFromString:datepictxt.text];
NSManagedObjectContext *context = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).persistentContainer.viewContext;
NSManagedObject *entityNameObj = [NSEntityDescription insertNewObjectForEntityForName:@"Tasks" inManagedObjectContext:context];
[entityNameObj setValue:tasks.text forKey:@"taskname"];
[entityNameObj setValue:date forKey:@"date"];
[((AppDelegate*)[[UIApplication sharedApplication] delegate]) saveContext];
NSError *error = nil;
if (![context save:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}else {
NSLog(@"Your Data has been Saved!");
}
}
【问题讨论】:
-
如果你想保存 "10:45:32" 的
NSString则将其保存为字符串...不要将其转换为NSDate对象。 -
那我怎么跟时间比较呢。
-
所以只节省时间是不可能的..
-
OK - 如果您想比较“时间”而不是“字符串”,那么您需要了解什么是日期。你从
datepictxt得到一个字符串,你想把它保存为“时间”吗?试着解释一下你想做什么... -
我正在制作一个保存 TaskName、TaskDate 和 Tasktime 的应用程序......然后我想在时间到来时通知他们(如警报)......
标签: ios objective-c core-data nsdate