Reputation: 35
How to get correct date not by system date in php
For ex: actual date is 24/4/2013
, but I changed my system date is 25/4/2013
.
How can get correct date ie 24/4/2013
?
Upvotes: 1
Views: 428
Reputation:
Set the default time zone prior to use the date()
function.
For instance:
date_default_timezone_set('UTC');
// or
// date_default_timezone_set('Europe/Madrid')
echo date("Y-m-d H:i:s");
Upvotes: 0
Reputation: 284
PHP can't inherently know that your system time is incorrect. As others have pointed out, you can query an authoritative source (similar to the solution offered here) instead.
EDIT: shortcut to the time server query example
Upvotes: 2
Reputation: 48599
http://tf.nist.gov/tf-cgi/servers.cgi
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Upvotes: 2