I have a page that shows future events along with the date (server time).
I need some method to display the date in user time.
Example:
Oct, 26 13:48:23 (server)
Oct, 26 14:48:23 (user time (UTC +1)) -> event info
What I have so far:
<?php
$sql=mysql_query("SELECT * FROM table") or die("Come back later");
while($row=mysql_fetch_array($sql)) {
echo date('M, d H:i:s', strtotime ($row['date'])).' -> '.$row['info'];
}
?>
With the diffence I want to detect user timezone.
Thank you.
EDIT
I know I should not be using mysql_*
If you’re ok with doing the conversion to the user’s time zone in JavaScript, you could do the following:
PHP
JavaScript (With jQuery for Readability)
If you want to render the dates in the format:
Oct, 26 13:48:23, you could do this:Then use
$this.text(dateString);to inject it into the dom.