Bart De Reu
Bart De Reu

Reputation: 27

Javascript time vs PHP time , not the same

i'm having a (older) mobile webpage that shows the current time in the footer of that page. Now i've added some PHP code to it, to have the user select a starting time of a working timer.

I noticed that the Javascript time is 2 minutes ahead of the PHP time.

JS :

var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
document.write(hours + ":" + minutes)

PHP :

echo date('H:i');

as i said, the difference is about 2 minutes, how is that even possible? both should be server time ??

Upvotes: 0

Views: 1539

Answers (2)

haMzox
haMzox

Reputation: 2109

JS shows client side time. PHP shows time which is on server.

Upvotes: 4

Simos Fasouliotis
Simos Fasouliotis

Reputation: 1390

Javacript is the time of the user...eg it may be 2 minutes if my pc time is 2 minutes ahead, or it might be difference in hours if different timezone from server!!

Php will always show server's time.

Upvotes: 1

Related Questions