Avatar of Vipin Kumar
Vipin KumarFlag for India

asked on 

How to make PHP use my system time

Hi,

Is it possible to to make PHP use server date and time instead of the timezone mentioned in php.ini file, i.e. if I change my server's date and time it should automatically use the same date and time.

Thanks in advance.
PHPApache Web Server

Avatar of undefined
Last Comment
skullnobrains
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Looking a bit more for ways to ask the server for its current date/time, you might be able to use exec() and run the date command.  Full disclosure: I have never tested this, nor even thought about it very much!
http://stackoverflow.com/questions/18458839/how-to-get-the-current-date-and-time-in-the-terminal-and-set-a-custom-command-in
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Windows servers use 'local time' but Linux servers do not use local time, their clocks are almost always set to GMT (Greenwich Mean Time) or Europe/London which is essentially the same thing.  Software running on Linux is expected to set their timezone to get the correct local time.
Avatar of skullnobrains
skullnobrains

you can read the system's timesone from /etc/timezone or possibly $ENV['TZ'] and then use what ray posted or possibly ini_set the timezone or use the default_timezone_set() function so the regular date commands will behave like you want.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo