To get timestamps to be in the user's time period, I have set up a timezone conversion tool with PHP for my posting system. Basically the user sets their own timezone through a dropdown, and this is stored on the database as a PHP timezone - so if I select GMT, the value in the database would be Europe/London
.
The idea is then to take this from the database and plug it into a timezone conversion piece of code, but this presently isn't converting anything at all. Can anyone see the problem?
doMessage.php
$date = date("Y-m-d G:i:s");
$user_tz = $result['time'];
$schedule_date = new DateTime($date, new DateTimeZone($user_tz) );
$schedule_date->setTimeZone(new DateTimeZone('UTC'));
$date = $schedule_date->format('Y-m-d H:i:s');
core/init.php
<?php
session_start();
$db = new PDO('this is all correct');
if(isset($_SESSION['id'])) {
$i = $_SESSION['id'];
$query = $db->prepare("SELECT * FROM users WHERE id=:i");
$query->bindParam(":i",$i);
$query->execute();
$result = $query->fetch();
$ver = $result["activated"];
if($ver == 0) {
echo "Please <a href='activate.php'>verify your account.</a>";
}
}
else {
echo "Please <a href='login.php'>log in.</a>";
$guest = True;
}
To get current date and time of GMT, just this is enough:
date_default_timezone_set('GMT');
$current_date = date("Y-m-d h:i:s A T")
echo $current_date;
This outputs 2013-12-30 5:30:20 AM GMT