php - 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 页面中,仍然返回一个空字符串。
有人有想法吗?
解决方案
也许您应该使用该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));
推荐阅读
- mysql - MySQL 从不要求输入密码
- angular - Angular dist 文件夹(构建后)如何与多个项目一起使用
- arrays - 如何在c中从数组的开头插入开始迭代的元素?
- xml - 根据python中的属性对xml进行排序
- javascript - 为什么 Javascript 在我的 UWP 应用程序的 webview 中不起作用?
- powershell - 取回变量属性
- javascript - Vue 无法检查最近未选中的复选框,甚至它的绑定
- javascript - 如何将数组转换为字符串并通过 alert() 函数检查?
- kotlin - 为什么 CoroutineExceptionHandler 只能在 coroutineContext 为 MainScope() 时执行启动?
- ruby-on-rails - Rails 管理员日期字段