开发者

how do i set the time in php?

开发者 https://www.devze.com 2023-01-08 04:45 出处:网络
<?php date_default_timezone_set(\"Spain/Madrid\"); $date=date(\"H:i:s\"); 开发者_如何学JAVA echo $date;
<?php

date_default_timezone_set("Spain/Madrid");

$date=date("H:i:s");
开发者_如何学JAVA
echo $date;
?>

how can i set the date to my location?

i get this when i run the script Notice: date_default_timezone_set() [function.date-default-timezone-set]: Timezone ID 'Espana/Madrid' is invalid

i know Spain/Madrid is not recognized, but how can i fix it?


Try

date_default_timezone_set("Europe/Madrid");


I typically use ini_set() :

ini_set('date.timezone', 'Europe/Madrid');


try Europe/Madrid


Take a look at http://www.php.net/manual/en/timezones.php


You'll find the list of the supported timezones in the documentation.


Here are the supported time zones in PHP


<?php
   date_default_timezone_set('Europe/Madrid');
   $date=date("H:i:s");
   echo $date;
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号