CodeIgniter Forums
Library: "Dates and Times" - 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: Library: "Dates and Times" (/showthread.php?tid=72676)



Library: "Dates and Times" - fapth - 01-22-2019

Hello Guys,

i wanne display the time in an other timezone. So tried this:
PHP Code:
        $time  Time::createFromTimestamp(1548131795'America/Chicago''en_US');
        
$time2 Time::createFromTimestamp(1548131795,'Europe/Berlin','de_DE');
        
        echo 
$time2->getTimeStamp().'<br />';
        echo 
$time->getTimeStamp().'<br />';
        echo 
 $time2->toLocalizedString($this->currentUser['TimeFormat']).'<br />';
        echo  
$time->toLocalizedString($this->currentUser['TimeFormat']); 
 
So what i get is this:
_____________________
1548128195
1548153395
22.36.2019 04:36:35
22.36.2019 04:36:35
____________________

I expected to get different times. Because when i wanne make a call with someone in an other timezone... he need his "time" in his format and i need it in mine. Do I use the library wrong ?

Thanks, guys


RE: Library: "Dates and Times" - albertleao - 01-22-2019

I highly recommend using https://carbon.nesbot.com/docs/ library for dates. It's the easiest way to handle dates including timezones.


RE: Library: &quot;Dates and Times&quot; - fapth - 01-22-2019

thx for this good tip. But shouldnt be this in the new CI 4 included? I will try your advise and comment.