Back to Top

How To Get Present Time Of Any Time Zone In Opencart

Updated 17 March 2016

Normally we can get local date and time by using php date function but today we will learn to get present time of different time zone. Here is the code

$date = new DateTime('2014-06-1', new DateTimeZone('America/Mexico_City'));
$zone = $date->format('P');
$query = "SELECT CONVERT_TZ(NOW(), @@session.time_zone, '$zone') as time;";
$data = $this->db->query($query)->row;
$time = date("Y-m-d H:i:s", strtotime($data['time']));   

If we print the $date then it gives DateTime object

DateTime Object
(
    [date] => 2014-06-01 00:00:00.000000
    [timezone_type] => 3
    [timezone] => America/Mexico_City
)

If we print the $zone then it gives

-05:00


If we print the $data then it gives
Array
(
    [time] => 2016-02-17 13:44:42
)  

If we print the $time then it gives


2016-02-17 13:52:59

Searching for an experienced
Opencart Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home