为了便于以后使用Objective-C日期格式化程序进行格式化,最好的存储日期格式是什么?日期将从unix时间戳开始,然后变成最容易处理的格式,存储在SQLite3数据库中,然后使用日期格式化程序进行检索和操作。我可以只使用时间戳吗?或者更好地将它转换为,比如说,YYYY/mm/dd,或者类似的东西。
发布于 2011-04-29 00:28:07
我认为为了便于排序,您应该以YYYYMMDDHHMMSS格式存储它。
你是不是直接写sqlite代码?为什么不使用诸如Core data (底层数据存储是sqlite)这样的托管数据框架,这将使您的工作变得更容易。这个小示例使用NSSortDescriptor按FileDate列进行排序。AssetItem是一个NSManagedObject子类
NSFetchRequest *nsrequest = nil;
NSEntityDescription *entity = nil;
NSError *error;
// check to see if the scene exists (could have been downloaded previously)
nsrequest = [[NSFetchRequest alloc] init];
entity = [NSEntityDescription entityForName:@"AssetItem" inManagedObjectContext:managedObjectContext];
[nsrequest setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"FileDate" ascending:NO] autorelease]]];
[nsrequest setEntity:entity];
NSArray *objs = [[managedObjectContext executeFetchRequest:nsrequest error:&error] retain];
for (AssetItem *item in objs) {
NSLog(@"file date is: %@", [item FileDate]);
}
[objs release];
[nsrequest release];
您可以使用内置的Xcode数据建模器工具进行很多建模。
https://stackoverflow.com/questions/5821625
复制相似问题