php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68871 strftime returns wrong timestamp with date_default_timezone_set
Submitted: 2015-01-21 08:04 UTC Modified: 2015-02-01 04:22 UTC
From: ricky at ez2 dot us Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 5.5.20 OS: Ubuntu 14.04 x64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-01-21 08:04 UTC] ricky at ez2 dot us
Description:
------------
strftime with %s format returns wrong value.

Test script:
---------------
<?php
//php.ini date.timezone = Asia/Taipei (UTC +0800)
date_default_timezone_set('UTC');
$time = time();
$time2 = strftime('%s', $time);
if($time != $time2){
    echo "something wrong"; 
}
else{ 
    echo "nothing";                
}

Expected result:
----------------
nothing

Actual result:
--------------
something wrong

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-21 10:35 UTC] ajf@php.net
-Package: PHP Language Specification +Package: Date/time related
 [2015-01-21 10:35 UTC] ajf@php.net
This has nothing to do with the language specification. Please choose categories accurately.
 [2015-01-21 11:58 UTC] derick@php.net
-Status: Open +Status: Feedback
 [2015-01-21 11:58 UTC] derick@php.net
I can not reproduce this with PHP 5.5.21:

derick@whisky:~ $ cat /tmp/68871.php
<?php
date_default_timezone_set('UTC');
$time = time();
$time2 = strftime('%s', $time);
var_dump( $time, $time2 );
?>

derick@whisky:~ $ php -ddate.timezone=Asia/Taipei /tmp/68871.php 
int(1421841507)
string(10) "1421841507"

What do you see different here?
 [2015-01-21 15:43 UTC] ricky at ez2 dot us
-Status: Feedback +Status: Open
 [2015-01-21 15:43 UTC] ricky at ez2 dot us
I use online php tester,but got wrong result.

http://sandbox.onlinephpfunctions.com/code/d41ddc29adee7a0f4aba6e4dd587c2ddee33c1a0
 [2015-01-21 18:14 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2015-01-21 18:14 UTC] aharvey@php.net
What is your TZ environment variable set to?
 [2015-02-01 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 05:03:34 2021 UTC