鍍金池/ 問答/PHP/ PHP中獲取文件創(chuàng)建、修改時間正確嗎?

PHP中獲取文件創(chuàng)建、修改時間正確嗎?

在mac上獲取到的時間和實際情況為何不符?現(xiàn)在問題是,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沒有文件創(chuàng)建時間,只有inode修改時間。那么這種情況下就沒辦法知道文件的創(chuàng)建時間了嗎?

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

圖片描述

圖片描述

本地時間正確
圖片描述

回答
編輯回答
怣人

filemtime 獲取 最后修改時間這個是正常的. 只是一個是24小時制, 一個是12小時制.
filectime 獲取inode修改時間
fileatime 取得文件的上次訪問時間

2018年3月4日 13:26
編輯回答
舊螢火

你要確保本地服務(wù)器的時間上是準確的,這樣就會對了

2017年12月18日 09:59