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);
}

https://img1.mukewang.com/5c8f3f1a0001a7d108000090.jpg

https://img1.mukewang.com/5c8f3f1b00012a1006680296.jpg

本地时间正确
https://img3.mukewang.com/5c8f3f1c0001523a08000337.jpg

牧羊人nacy
浏览 436回答 2
2回答

月关宝盒

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

POPMUISE

你要确保本地服务器的时间上是准确的,这样就会对了
打开App,查看更多内容
随时随地看视频慕课网APP