0

Im trying to assign a variable with timezone info that will change the time of info saved in a database.

Here is my code that doesn't work:

<?php 
$timeZone = "- 3600";
$date = date('His', time() $timeZone);
echo $date;
?>

But when I do this it works...

<?php 
$date = date('His', time() - 3600);
echo $date;
?>

Why won't the variable work in there?

4

3 回答 3

1

It's invalid syntax. Change $timeZone to an integer and add it to time().

$timeZone = -3600;
$date = date('His', time() + $timeZone);
echo $date;

See a demo

于 2013-04-26T01:17:47.900 回答
1

If you want to convert to another timezone, there is a proper way of doing it: UTC Date/Time String to Timezone

于 2013-04-26T01:18:37.753 回答
0

You can't embed binary operators in a string and expect them to execute. You'll need to do something like this:

<?php 
$timeZone = -3600;
$date = date('His', time() + $timeZone);
echo $date;
?>
于 2013-04-26T01:17:29.790 回答