PHP > Set Default Timezone

后端 未结 2 1126
萌比男神i
萌比男神i 2021-01-23 17:35

We want to set the timezone up as a variable in PHP to account for different timezones / daylight savings.

Our code works perfectly when hard coded:

date         


        
相关标签:
2条回答
  • 2021-01-23 17:57

    Try this code:

    $setzone = "Australia/Brisbane";
    date_default_timezone_set("$setzone");
    
    0 讨论(0)
  • 2021-01-23 18:06

    if you will add quote then variable behaving as string for instance

    $setzone = "Australia/Brisbane";
    echo '".$setzone."';
    

    Output :

    ".$string." //output as string not a variable value

    So you need to remove quote when passing string into variable

    date_default_timezone_set('".$setzone."');
    

    to

    date_default_timezone_set($setzone);
    
    0 讨论(0)
提交回复
热议问题