CodeIgniter Forums
Time() not same? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Time() not same? (/showthread.php?tid=81033)



Time() not same? - mylastof - 01-17-2022

Code:
$now = Time::now();
$new_now = Time::createFromTimestamp($now->timestamp);

$new_now create from $now->timestamp
but $new_now not showing the same Time with $now
even I add timeZone in the createFromTimestamp()
The time not change.

Is this a bug?

Code:
// $now with (int)1642422355
object(CodeIgniter\I18n\Time)[78]
  protected 'timezone' =>
    object(DateTimeZone)[80]
      public 'timezone_type' => int 3
      public 'timezone' => string 'America/Chicago' (length=15)
  protected 'locale' => string 'en' (length=2)
  protected 'toStringFormat' => string 'yyyy-MM-dd HH:mm:ss' (length=19)
  public 'date' => string '2022-01-17 06:25:55.438431' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'America/Chicago' (length=15)

Code:
// $new_now with (int) 1642422355
object(CodeIgniter\I18n\Time)[81]
  protected 'timezone' =>
    object(DateTimeZone)[82]
      public 'timezone_type' => int 3
      public 'timezone' => string 'UTC' (length=3)
  protected 'locale' => string 'en' (length=2)
  protected 'toStringFormat' => string 'yyyy-MM-dd HH:mm:ss' (length=19)
  public 'date' => string '2022-01-17 12:25:55.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'UTC' (length=3)



RE: Time() not same? - BilltheCat - 01-17-2022

Interesting, I'm getting similar results.

2022-01-17 13:57:53
2022-01-17 19:57:53
PHP Code:
<?php

namespace App\Controllers;
use 
CodeIgniter\I18n\Time;
class 
Timetest extends BaseController
{

    public function index()
    {
        $now = new Time('now''America/Chicago''en_US');
        $new_now Time::createFromTimestamp($now->timestamp'America/Chicago''en_US');

        print $now;
        echo "<br>\n";
        print $new_now;
    }





RE: Time() not same? - kenjis - 01-19-2022

This was fixed in the latest develop branch, and would be included in the next 4.2.0.
https://github.com/codeigniter4/CodeIgniter4/pull/5588