I want to be able to get the time of the person using the PHP script.
I don't know what time zone they will be in, etc.
Is there not a way of just saying 'get the time of the user' rather than setting timezones?
?> Note that the PHP date() function will return the current date/time of the server!
Answer: Use the PHP date() Function You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.
In the below example, we have date 2019-09-15 in YYYY-MM-DD format, and we will convert this to 15-09-2019 in DD-MM-YYYY format. $orgDate = "2019-09-15"; $newDate = date("d-m-Y", strtotime($orgDate)); echo "New date format is: ".
No. There are only three ways to get the time zone of the user:
Ask the user
Use JavaScript to check the time client-side and send it to your server with an AJAX request, a cookie, etc. -- only works if JS is enabled and doesn't work for the first request
Use an IP-to-location database to locate the user and determine their time zone from the location -- more than 5% of the time with any commercial database, your location at the city level will be wrong
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With