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

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

在mac上獲取到的時(shí)間和實(shí)際情況為何不符?現(xiàn)在問(wè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));

自己搜到的資料,說(shuō)是unix沒(méi)有文件創(chuàng)建時(shí)間,只有inode修改時(shí)間。那么這種情況下就沒(méi)辦法知道文件的創(chuàng)建時(shí)間了嗎?

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

圖片描述

圖片描述

本地時(shí)間正確
圖片描述

回答
編輯回答
怣人

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

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

你要確保本地服務(wù)器的時(shí)間上是準(zhǔn)確的,這樣就會(huì)對(duì)了

2017年12月18日 09:59