Reputation: 109
i'm using a shared server with default timezone -06:00 (US) but all the users in the website are in +03:00 timezone. can i change the time displayed to the user by only using php because there is no way to modify the server settings. i searched a lot and tried to set the timezone using .htaccess using this code
SetEnv TZ America/Indianapolis
and also i added this code at the beginning of the php code
putenv("TZ=Asia/Baghdad");
date_default_timezone_set("Asia/Baghdad");
but still no change
this is how i display the date and time:
echo date('Y-m-d / h:i a', strtotime($articles_info['date']));
It maybe an easy solution but i still in the process of learning. thanks alot..
Upvotes: 0
Views: 229
Reputation: 79024
Since there is no timezone as part of the date/time $articles_info['date']
, how does PHP know to change the date/time to the default? As far as PHP knows, the date/time is already in the default timezone. Tell it the timezone of the provided date/time:
echo date('Y-m-d / h:i a', strtotime($articles_info['date'] . ' America/Chicago'));
-6:00 should be Central Time, but since we don't know if it's standard (CST) or Daylight (CDT), try America/Chicago
.
Upvotes: 2