How do I know the time and date of a location with PHP?

5

I want to store in a variable the current time of Portugal and in another variable the current date of Portugal.

How can I do this?

    
asked by anonymous 23.12.2016 / 17:21

2 answers

3

You can do this:

date_default_timezone_set('Europe/Lisbon');

$dia = date('Y-m-d'); // 2016-12-24
$hora = date('G:i'); // 16:29

DEMONSTRATION

Note that in the demo, the time is not good, but should be because of the ideone platform.

    
23.12.2016 / 17:25
1

Set date_default_timezone_set to Europe/Lisbon and see working here at ideone :

date_default_timezone_set('Europe/Lisbon');

$date = time();
$date = date('Y-m-d', $date);
$hour = date('H:i:s', $date);
echo "Data: ".$date."\n";
echo "Hora: ".$hour;

You can check the timezones support list in PHP .

    
23.12.2016 / 17:33