'How to set the time zone with php [duplicate]
I'm trying to set the time in PHP, but I don't know to set the time zone.
<?PHP
$currentDateTime = time();
$newDateTime = date('h:i A', strtotime($currentDateTime));
?>
<input type="text" name="time" value="<?php echo $newDateTime; ?>"></input>
Solution 1:[1]
You can do this by adding the following code:
<?php
date_default_timezone_set('Africa/Johannesburg');
echo date('H:i:s', time());
?>
Solution 2:[2]
<?php
date_default_timezone_set('America/Los_Angeles');
$script_tz = date_default_timezone_get();
if (strcmp($script_tz, ini_get('date.timezone'))){
echo 'Script timezone differs from ini-set timezone.';
} else {
echo 'Script timezone and ini-set timezone match.';
}
?>
Solution 3:[3]
You can do this by using following code :
<?php
date_default_timezone_set('America/Los_Angeles');
$any_variable = date_default_timezone_get();
?>
After this you can use the any_variable to compare , echo or what ever you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | MD ARIFUL HAQUE |
| Solution 3 |
