php得到当前时间戳,一个月后的时间戳,一年后的时间戳
在 PHP 中,你可以使用 time()
函数来获取当前时间的 Unix 时间戳。对于一个月后和一年后的时间戳,可以使用 strtotime()
函数。以下是如何实现的:
$now = time(); // 获取当前时间戳
echo "现在的时间戳: {$now}\n";
$oneMonthLater = strtotime("+1 month"); // 获取一个月后的时间戳
echo "一个月后的时间戳: {$oneMonthLater}\n";
$oneYearLater = strtotime("+1 year"); // 获取一年后的时间戳
echo "一年后的时间戳: {$oneYearLater}\n";
在这个例子中,time()
函数返回了当前时间的 Unix 时间戳,strtotime("+1 month")
和 strtotime("+1 year")
返回了一个月后和一年后的 Unix 时间戳。这里的 "+1 month" 和 "+1 year" 是相对于当前时间的日期字符串。