计算服务器和用户时间之间的差异

I'm writing a simple javascript to calculate the time difference between server and user time. But something is going wrong.

If I catch the javascript and php date i have:

date("M d Y h:i:s A")
php date : Wed Jun 27 2012 04:10:41 AM  

new Date()
J S date : Wed Jun 27 2012 10:10:40 GMT+0200 (CEST)   

This is correct! I have two different time for local and server time.

Now if I take the seconds time... something goes wrong:

(php: date("U"))
sec PHP: 1340784640    

(js new Date().getTime()/1000 )
sec J S: 1340784640

I got the same time!

Can you help me to fix it ?

Thanks!

date("U") and new Date().getTime() return the Unix timestamp which is defined as seconds elapsed since January 1st, 1970 UTC. The current locale's timezone is not taken into account.

Use date('Z') to get the timezone offset in PHP (in seconds) and new Date().getTimezoneOffset() in JavaScript (in minutes).