Welcome Guest, Not a member yet? Register   Sign In
Time() not same?
#1

(This post was last modified: 01-17-2022, 05:27 AM by mylastof.)

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)
Reply
#2

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;
    }


Reply
#3

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB