首页 > 解决方案 > strftime 给我返回空字符串

问题描述

我有一个非常简单的错误,我不明白为什么stftime PHP 函数返回一个空字符串,而语法和代码似乎都正确。

我得到以下代码:

$next_high_tide_date = strtotime($next_high_tide_date);
// FROM '2021-05-22 00:26:00' TO (timestamp) 1621635960
$next_high_tide_date_day = strtoupper(strftime('%A %d %B', $next_high_tide_date));
// THIS RETURNS ME THE RIGHT DAY DATE
$next_high_tide_date_hour = strtoupper(strftime('%k H %M', $next_high_tide_date));
// THIS RETURNS ME AN EMPTY STRING

第一次声明后我的$next_hight_tide_date值等于1621643160(时间戳)。我在网上检查了strftime 检查器,我的代码是正确的,但在我的 php 页面中,仍然返回一个空字符串。

有人有想法吗?

捕获我的代码

标签: phptimestampstrftime

解决方案


也许您应该使用该date()函数来格式化您的时间戳。

$next_high_tide_date = "2021-05-22 00:26:00";
$next_high_tide_date = strtotime($next_high_tide_date);
$next_high_tide_date_day = strtoupper(date('l d F', $next_high_tide_date));
$next_high_tide_date_hour = strtoupper(date('H \H i', $next_high_tide_date));

尝试这个

或使用%H代替%k

$next_high_tide_date = "2021-05-22 00:26:00";
$next_high_tide_date = strtotime($next_high_tide_date);
$next_high_tide_date_day = strtoupper(strftime('%A %d %B',$next_high_tide_date));
$next_high_tide_date_hour = strtoupper(strftime('%H H %M',$next_high_tide_date));

推荐阅读