I have change system time then after displaying time an displayi correct time

Dani AI

Generated

Short answer for : PHP reads the OS clock. If you manually change the system time, PHP functions (time(), date(), DateTime) will reflect that changed clock. As requested more detail, here are quick diagnostics and practical fixes.

Check what PHP sees and the configured timezone:

echo date_default_timezone_get() . "\n";
echo date('Y-m-d H:i:s') . "\n";

Setting the PHP timezone with date_default_timezone_set() only changes the timezone, not a wrong hardware/system clock. See the PHP DateTime and timezone docs for details: DateTime class and date_default_timezone_set.

Two recommended fixes

  • Server-level (preferred): Sync the machine with NTP (ntpd/chrony/systemd-timesyncd). That corrects the real system clock so every program (including PHP) is accurate. Background: https://www.ntp.org/
  • App-level (when you cannot change server clock): Query an authoritative remote time and use that value for display. Example using an HTTP Date header (simple fallback):
$headers = get_headers('https://www.google.com', 1);
$time = isset($headers['Date']) ? strtotime($headers['Date']) : time();
echo gmdate('Y-m-d H:i:s', $time);

Cautions: outbound HTTP/NTP calls can be blocked by hosting, and relying on a single remote host is brittle — prefer dedicated time APIs or NTP. For production, always store and work in UTC and keep the server clock synced.

Recommended Answers

All 2 Replies

I want displaying correct time

and where you want to display time please provide code and more detail for help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.