3

以下代码正在运行。预计会返回应用程序的上次发布日期,但是...

// e.g. entryPath = @"/Applications/Evernote.app"

struct stat output;
int ret = stat([entryPath fileSystemRepresentation], &output);
if (ret == 0)
{
    struct timespec accessTime = output.st_atimespec;
    NSDate * date1 = [[NSDate dateWithTimeIntervalSince1970:accessTime.tv_sec]
            dateWithCalendarFormat:nil timeZone:[NSTimeZone localTimeZone]];

    // and the 10.6+ version: (the result was always the same for me)
    NSDate * date2 = [[[[NSURL fileURLWithPath:entryPath]
            resourceValuesForKeys:[NSArray arrayWithObject:NSURLContentAccessDateKey]
                            error:nil]
            objectForKey:NSURLContentAccessDateKey]
            dateWithCalendarFormat:nil timeZone:[NSTimeZone localTimeZone]];
}

它返回非常奇怪的日期,通常在今天或昨天凌晨 3:00-3:30 附近,当时我实际上正在睡觉。但在那之后,我在 Finder 中单击“获取信息”,它会显示真正的上次发布日期(通常小于date1date2,但也可以相等)。如何以编程方式获取它? Finder 获取信息:上次打开日期

4

0 回答 0