0

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.

Tulon
  • 4,011
  • 6
  • 36
  • 56
Fredrik Johansson
  • 1,301
  • 1
  • 13
  • 26
  • possible duplicate of [How to get nsdate with millisecond accuracy?](http://stackoverflow.com/questions/5359977/how-to-get-nsdate-with-millisecond-accuracy) – markhunte May 11 '14 at 15:57
  • No, I don't think so. But Torino's answer confirms my assumptions that I need to solve this in another way. – Fredrik Johansson May 11 '14 at 16:26

1 Answers1

1

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.

Torino
  • 588
  • 2
  • 9
  • Yea, I know it's a double, but I was concerned about the missing fractional part. I keep this question open for a while just to see how this kind of problem usually is solved. Thanks! – Fredrik Johansson May 11 '14 at 16:31
  • Ok, I think I'll solve my problem by naming the files in a increasing way, and then use the file names to sort the files. Just if anybody else runs into this. – Fredrik Johansson May 11 '14 at 19:15