开发者

Is possible to know the user time and date in php?

开发者 https://www.devze.com 2023-01-28 14:00 出处:网络
is possible to know the local time and date of the user who opens a php page? (not开发者_StackOverflow社区 server side time and date). If the answer is no, can show me an example of javascript combine

is possible to know the local time and date of the user who opens a php page? (not开发者_StackOverflow社区 server side time and date). If the answer is no, can show me an example of javascript combined with php? (im not a java developer) Thanks.


First, Java is not JavaScript…

And you could do this through hidden <input> in HTML.

<input id="user-time" name="user-time" type="hidden" />

and JavaScript function to associate with form on submit:

function submit() {
    document.getElementById("user-time").value = (new Date()).getTime();
}

After this, parse the timestamp in your server-side PHP.


Yes but it wouldn't be a 100% accurate. Using their IP you can determine what timezone they are in. See this question about doing just that.

Once you have their timezone you can use date_timezone_set to set the appropriate timezone in PHP and pull their date/time information.

0

精彩评论

暂无评论...
验证码 换一张
取 消