Forum Moderators: coopster

Message Too Old, No Replies

PHP and Time Zone: Display data based on localtime

Localtime of the visitor

         

Habtom

2:00 pm on Jul 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How to do this in a good way:

Find local time of the visitor [the visitor's local machine] and pull out data from the database based on his machines local time (can be wrong or right no problem with that).

What do you suggest?

Habtom

benevolent001

2:11 pm on Jul 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not sure what exactly we want to make here

But getting visitor time is always possible by javascript as you know , but what you mean by showing data based on local time? Data shown will always be latest picked from database i guess even if sever and local visitor are in diff time zone

Can you give example what we want to do?

Gian04

2:25 pm on Jul 18, 2007 (gmt 0)

10+ Year Member



The way I understand what Habtom want to accomplish is:

Create a script wherein it will show data /content depending on the user local time.

Ex. If the users time is 1:00 AM it will retrieve record 1-10 if its 2:00 it will retrieve 11-20...

Habtom

5:37 am on Jul 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Gian04,
yes that is exactly what I wanted. To get the local time of the visitor, and display data based on his local time on his machine.

On a few trials I got what I wanted. May be it can be helpful to somebody else so I post it here:

<?php
//code
?>
<script type="text/javascript">
function GetTime() {
var now = new Date();
//var currenthour = now.getHours();
//var currenttime = now.getMinutes();
//var currentdate = now.getDate();
//var offset = now.getTimezoneOffset();
document.write(now);
}
</script>
<?php
$time_current = "<script language=javascript>GetTime();</script>";
echo "Time: ". $time_current;
?>

[edited by: Habtom at 5:38 am (utc) on July 19, 2007]