PHP中获取文件创建、修改时间正确吗?

在mac上获取到的时间和实际情况为何不符?现在问题是,filemtimefilectime一样了

echo date('Y-m-d H:i:s', filemtime($file));
echo date('Y-m-d H:i:s', filectime($file));
echo date('Y-m-d H:i:s', fileatime($file));

自己搜到的资料,说是unix没有文件创建时间,只有inode修改时间。那么这种情况下就没办法知道文件的创建时间了吗?

https://stackoverflow.com/que...

Use filectime. For Windows it will return the creation time, and for Unix the change time which is the best you can get because on Unix there is no creation time (in most filesystems).

Note also that in some Unix texts the ctime of a file is referred to as being the creation time of the file. This is wrong. There is no creation time for Unix files in most Unix filesystems.

记录一条,楼下提供的参考资料

http://php.net/manual/zh/func...
If you need file creation time on Mac OS X:

<?php
if ($handle = popen('stat -f %B ' . escapeshellarg($filename), 'r')) {
    $btime = trim(fread($handle, 100));
    echo strftime("btime: %Y.%m.%d %H:%M:%S\n", $btime);
    pclose($handle);
}

图片描述

图片描述

本地时间正确
图片描述

阅读 4.1k
2 个回答

filemtime 获取 最后修改时间这个是正常的. 只是一个是24小时制, 一个是12小时制.
filectime 获取inode修改时间
fileatime 取得文件的上次访问时间

你要确保本地服务器的时间上是准确的,这样就会对了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题