Pergunta

The code snippet below is taken from a greater context. I want to sort files in order of their creation time. The problem is that d seems to be in seconds although I guess that the resolution of NSDate is much higher. Is the resolution of the stored time in the "iOS" file system only in seconds?

The files are created within fractions of milliseconds, so I need a higher resolution. Any suggestions?

for(NSURL *it in archFiles)
{
  NSDate *date;
  [it getResourceValue:&date forKey:NSURLCreationDateKey error:nil];
  double d = date.timeIntervalSince1970;
  NSLog(@"%@: timestamp:%f", it.path, d);
}

The printout (I've removed parts of the path): /private/var/....archive: timestamp:1399819259.000000

I've tried it in both "iOS simulator" and the "iPad emulator" with the same result. I guess the 6 zeroes at the end is not pure coincidence. :)

Just want to add that a valid date is shown when I hover over date in the debugger.

Foi útil?

Solução

NSDate has a higher resolution than 1 second. But the file system (HSFX on iOS) doesn't. So if you read the creation date of a file, the fractional part will always be zero.

In addition, you don't output a NSDate but a double number. So the six zeros at the end are an artifact from the %f formatting pattern.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top