次のコードが機能しています。アプリの最終起動日を返すことが期待されていますが...
// 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 で [Get Info] をクリックすると、実際の最終起動日が表示されます (通常はdate1
とよりも小さいですdate2
が、等しい場合もあります)。プログラムで取得する方法は?