Home >Backend Development >PHP Tutorial >How Can I Get Client-Side Time in PHP?

How Can I Get Client-Side Time in PHP?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-15 11:51:031098browse

How Can I Get Client-Side Time in PHP?

Accessing Client-Side Time in PHP

In PHP, using the date() function returns the time from the server where the code is running. However, there might be instances when you need to retrieve the local time of the user who is accessing the website.

To obtain the client-side time, you can utilize a JavaScript solution:

echo '<script type="text/javascript">
var x = new Date()
document.write(x)
</script>';

This script will execute on the client's browser and display the local time.

The above is the detailed content of How Can I Get Client-Side Time in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn