struct stat output; //int ret = stat([[[openPanel filenames] lastObject] UTF8String],&output); int ret = stat([[[openPanel filenames] lastObject] fileSy@R_404_6563@Representation],&output); // error handling omitted for this example struct timespec accesstime = output.st_atimespec; NSDate *aDate = [NSDate dateWithTimeIntervalSince1970:accesstime.tv_sec]; NSLog(@"Access Time %d,%@",ret,aDate);
根据上面的代码,我尝试了UTF8String和fileSy@R_404_6563@Representation,但两者都给了我当前的日期和时间.如果我做错了,请告诉我.
解决方法 使用stat系统调用的C方式将在Objective-C中工作.例如
struct stat output;int ret = stat(afilePath,&output);// error handling omitted for this examplestruct timespec accesstime = output.st_atime;
您应该通过将-fileSy@R_404_6563@Representation发送到包含该路径的Nsstring来获取afilePath.
另一种获得所需方法的方法是在指向所需文件的文件URL之前构造NSURL,并使用-resourceValuesForKeys:error:获取NSURLContentAccessDate资源值.
总结以上是内存溢出为你收集整理的objective-c – 在Cocoa中查找文件的上次访问日期全部内容,希望文章能够帮你解决objective-c – 在Cocoa中查找文件的上次访问日期所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)