php - 如何获取在 PHP 中以秒为单位创建文件的时间
问题描述
我正在尝试创建一个脚本来删除 1 天前创建的文件,我需要计算该文件在几秒钟内创建了多长时间,但我不知道如何,有人可以帮忙吗?
解决方案
来自:https ://www.php.net/manual/en/function.filectime.php
您可以使用该filectime
功能获取文件的创建日期。该函数返回一个 unix 时间戳。然后,您可以从当前时间中减去该时间,以获得文件创建前的秒数。
<?php
# Get the creation date of the file in unix timestamp
$creationDate = filectime("myfile.txt");
# Subtract the creation date from the current time, to get the time difference in seconds
$secondsAgo = time() - $creationDate;
?>
请注意,在大多数 unix 系统上,它将返回最后修改日期而不是创建日期。这是因为在大多数 unix 系统上,创建日期并不像在 Windows 上那样存在。
推荐阅读
- java - Java lamba 参数类型未正确推断
- excel - 在 Excel 2007 中增加文本字符串中的最后一个数字
- python - 从 django-python 访问 Google 驱动器
- java - A* 路径查找在某些情况下会永远运行
- c - printf 显示“-858993460”或“╠╠╠╠╠╠╠╠”;这些是什么?
- javascript - 未捕获的错误:[$injector:modulerr] 将 Angular JS 与行星 9 一起使用时
- installation - 为什么我在安装过程中无法选择 Typo3 的数据库?
- google-chrome - 如何在 Chrome 无头中保存完整的 webapge
- ajax - Django 在服务器上的 ajax 之后重定向
- python - 检查一个点是否在 ConvexHull 中?