/    Sign up×
Community /Pin to ProfileBookmark

wrong php timezone when load code from ajax

I change the default timezone from (Europe/Berlin) to (Asia/Kuwait) by date_default_timezone_set() function
but when I change some code’s by javascript ajax it return to (Europe/Berlin) as default timezone why?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 10.2017 — Probably not enough info to really tell. A more robust solution would be to change the PHP default timezone in the php.ini file for the web server, if possible, otherwise in a project-level .htaccess file if allowed.

If you have to do it via the date_default_timezone_set() function, then you need to make sure it gets done for each and every file that gets called by your site's links and JavaScript requests.

Also, if the JavaScript itself is doing any time-related stuff, it may be defaulting to the user's local machine settings. (I'm not a JS expert, so if that seems to be the issue, you'll want to ask on the JavaScript forum here. ? )
Copy linkTweet thisAlerts:
@BofasauthorFeb 11.2017 — you'r right because Ajax response date/time in GMT format so I add date_default_timezone_set() function in each file that gets called

thanks for help
Copy linkTweet thisAlerts:
@wbportFeb 13.2017 — I am still new to php, but the JavaScript date/time function of[CODE]getTimezoneOffset()[/CODE] will return in minutes the difference between the user's time zone and GMT. It returns a positive number in the Western hemisphere and negative in the Eastern so you might have to negate it after dividing by 60.
×

Success!

Help @Bofas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...