Welcome Guest, Not a member yet? Register   Sign In
Time::createFromTimestamp always -2 hours in my local time
#2

(This post was last modified: 07-03-2022, 04:06 PM by kenjis.)

Cannot reproduce.

I see "3 July 2022 om 14:38".

Code:
diff --git a/app/Config/App.php b/app/Config/App.php
index 1a5e562dd..d1de17941 100644
--- a/app/Config/App.php
+++ b/app/Config/App.php
@@ -109,7 +109,7 @@ class App extends BaseConfig
      *
      * @var string
      */
-    public $appTimezone = 'America/Chicago';
+    public $appTimezone = 'Europe/Amsterdam';

    /**
      * --------------------------------------------------------------------------
diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php
index 7f867e95f..6d98547e8 100644
--- a/app/Controllers/Home.php
+++ b/app/Controllers/Home.php
@@ -2,10 +2,15 @@

namespace App\Controllers;

+use CodeIgniter\I18n\Time;
+
class Home extends BaseController
{
    public function index()
    {
-        return view('welcome_message');
+        $created_at = '2022-07-03 14:38:10';
+        $timmestamp = Time::createFromTimestamp( strtotime( $created_at ), app_timezone() ); // Correct, Europe/Amsterdam
+
+        return $timmestamp->toLocalizedString("d MMMM yyyy 'om' HH:mm");  // Always output with time:  12:38
    }
}

I got "12:38" on v4.1.9.

Upgrade to latest v4.2.1.
Reply


Messages In This Thread
RE: Time::createFromTimestamp always -2 hours in my local time - by kenjis - 07-03-2022, 04:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB