简体   繁体   中英

Why a file's creation timestamp is different from different device?

I use stat -t "%s" filename on MAC, then I get one line like:

16777223 9414940 -rwxr-xr-x 1 name staff 0 10838392 "1569834440" "1567413629" "1567413629" "1567413629" 4096 21176 0 filename

according to man stat , the second timestap( "1567413629" ) is creation timestamp of this file.

But when I use code in Objective-C to get a file's creation time, something odd happen. I get the creation time "1567413631" while I expected "1567413629" . The Objective Code is following:

NSDate * createDate = ((WMMediaAsset *)section.assets[index]).creationDate;
NSString * timestamp = [NSString stringWithFormat:@"%lld", (long long)([createDate timeIntervalSince1970])];

As I thought the creation timestamp is an absolute value record in the file inner. To copy a file to another device will not change the creation time of a file.

Am I wrong? Can you give some tips or remind me somewhere I should go find more information?

The creation date you are reading comes from the file system, not one from the file (meta)data itself eg A copied digital photo may contain an EXIF date when it was taken (and hence when the original file was created) which differs from the file system creation date of the copy.

Some systems may maintain the original creation date when copying a file, this is usually done above the file system level, eg a copy is first created, which gets the current time as its creation date, and then a system call is made to alter the creation date to that of the original.

As an example in macOS if a file is copied in the Finder the copy inherits its creation date from the original. However if the copy is done in the shell using cp the creation date is not inherited.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM