Welcome Guest, Not a member yet? Register   Sign In
the unix timestamp which returned by now() is not right
#1

[eluser]qwang[/eluser]
there's an api which need gmt unixstamp, but our users are different timezones
so when i get unix timestamp with now(), i found it's different

below is my test code:
Code:
$this->load->helper('date');
        date_default_timezone_set(tz_offset_to_name(timezones( 'UP8' )));
        echo "TIMEZONE    = ". date_default_timezone_get();
        echo "<br />";
        echo "CI now()     = " . unix_to_human(now(), TRUE, 'eu');
        echo "<br />";
        echo "CI stamp     = " . now();
        echo "<br />";
        date_default_timezone_set(tz_offset_to_name(timezones( 'UTC' )));
        echo "TIMEZONE    = ". date_default_timezone_get();
        echo "<br />";
        echo "CI now()     = " . unix_to_human(now(), TRUE, 'eu');
        echo "<br />";
        echo "GMT time    = " . gmdate('Y-m-d H:i:s', time());
        echo "<br />";
        echo "CI stamp     = " . now();

anyone meet this problem
thank you
#2

[eluser]Georgi Budinov[/eluser]
I tried this code:

Code:
$this->load->helper('date');
        date_default_timezone_set('Europe/Sofia');
        echo "TIMEZONE    = ". date_default_timezone_get();
        echo "<br />";
        echo "CI now()     = " . unix_to_human(now(), TRUE, 'eu');
        echo "<br />";
        echo "GMT time    = " . gmdate('Y-m-d H:i:s', time());
        echo "<br />";
        echo "CI stamp     = " . now();
        echo "<br />";
        date_default_timezone_set('Europe/Lisbon');
        echo "TIMEZONE    = ". date_default_timezone_get();
        echo "<br />";
        echo "CI now()     = " . unix_to_human(now(), TRUE, 'eu');
        echo "<br />";
        echo "GMT time    = " . gmdate('Y-m-d H:i:s', time());
        echo "<br />";
        echo "CI stamp     = " . now();

And the output looks fine for me: unix_to_human returns time for the selected timezone.




Theme © iAndrew 2016 - Forum software by © MyBB