Home » Php » datetime – how to get current time of a UAE in PHP

datetime – how to get current time of a UAE in PHP

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am using yii framework

I am using below to code to get time

<?php echo date('Y/m/d H:i:s') ?>

how can i current time of UAE?

How to&Answers:

Try this:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');

Answer:

Use date_default_timezone_set() :

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');