Doc #77840 [Com]: strftime("%s") returns false results
| From: | agus117 at hotmail dot com | Date: | Wed, 10 Feb 2021 18:26:40 +0000 |
| Subject: | Doc #77840 [Com]: strftime("%s") returns false results | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18519@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77840&edit=1
ID: 77840
Comment by: agus117 at hotmail dot com
Reported by: dc at ftb-esv dot de
Summary: strftime("%s") returns false results
Status: Open
Type: Documentation Problem
Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I've got here because %s and %T also returns 'false' on PHP 5.4.60. Works as intended
on 7.3+
strftime("%T", 1612978901); // expected "11:38:48" (on locale MX), but returns
boolean:false
strftime("%s", 1612978901); // also returns boolean:false
Previous Comments:
------------------------------------------------------------------------
[2019-04-03 20:03:08] dave_martin at mindspring dot com
Tangentially related, the use of %s with both strftime and gmstrftime on Windows does not produce
any output at all using PHP 7.3.3 64-bit thread safe.
Test script:
<?php
echo strftime ('%s',1546303600); // results in no output
echo gmstrftime('%s',1546303600); // results in no output
?>
------------------------------------------------------------------------
[2019-04-03 18:44:34] dc at ftb-esv dot de
Description:
------------
---
From manual page: https://php.net/function.strftime
---
Functions strftime() and gmstrftime() return (different) wrong results for format "%s". I
tested it with PHP 5.5.14 and PHP 7.2.5, bith with CLI and Apache. I used timestamps with and
without DST.
Test script:
---------------
<?PHP
header('Content-Type: text/plain; charset=utf-8');
$list = array(
1546303600, // 2018-01-01 00:46:40 UTC
1556703600, // 2019-05-01 09:40:00 UTC
);
echo "\ndate_default_timezone_set('UTC')\n";
date_default_timezone_set('UTC');
foreach ( $list as $time )
{
printf("\n%u\n%4s\n%s\n",
$time,
strftime('%s, %F %T %Z',$time),
gmstrftime('%s, %F %T %Z',$time) );
}
echo "\ndate_default_timezone_set('Europe/Berlin')\n";
date_default_timezone_set('Europe/Berlin');
foreach ( $list as $time )
{
printf("\n%u\n%4s\n%s\n",
$time,
strftime('%s, %F %T %Z',$time),
gmstrftime('%s, %F %T %Z',$time) );
}
?>
Expected result:
----------------
date_default_timezone_set('UTC')
1546303600
1546303600, 2019-01-01 00:46:40 UTC
1546303600, 2019-01-01 00:46:40 GMT
1556703600
1556703600, 2019-05-01 09:40:00 UTC
1556703600, 2019-05-01 09:40:00 GMT
date_default_timezone_set('Europe/Berlin')
1546303600
1546303600, 2019-01-01 01:46:40 CET
1546303600, 2019-01-01 00:46:40 GMT
1556703600
1556703600, 2019-05-01 11:40:00 CEST
1556703600, 2019-05-01 09:40:00 GMT
Actual result:
--------------
date_default_timezone_set('UTC')
1546303600
1546300000, 2019-01-01 00:46:40 UTC
1546300000, 2019-01-01 00:46:40 GMT
1556703600
1556700000, 2019-05-01 09:40:00 UTC
1556700000, 2019-05-01 09:40:00 GMT
date_default_timezone_set('Europe/Berlin')
1546303600
1546303600, 2019-01-01 01:46:40 CET
1546300000, 2019-01-01 00:46:40 GMT
1556703600
1556703600, 2019-05-01 11:40:00 CEST
1556700000, 2019-05-01 09:40:00 GMT
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77840&edit=1