to set default timezone in our php page, we can use PHP native function.
syntax:
for example, if you are in New York, your timezone is "America/New_York"
standard timezone for India is "Asia/Kolkata" or "Asia/Calcutta".
WHY we need to set timezone in our PHP page?
Consider your server in India and your client access your web page from America, In this situation you are getting date() or time() from your server using PHP, it will return server timezone. That means it will return Indian time.
So, you should change it to American timezone to get correct date() or time() from server.
You can put this in your header of footer php file to set timezone in all of your pages.
Timezone Array
If you are giving option to select timezone to user, you should list out all timezones in your select box. You can simply use this below function to do this. it will return array of timezones.
And you can use that array in your form like the above code.
syntax:
date_default_timezone_set('region/area');
for example, if you are in New York, your timezone is "America/New_York"
standard timezone for India is "Asia/Kolkata" or "Asia/Calcutta".
WHY we need to set timezone in our PHP page?
Consider your server in India and your client access your web page from America, In this situation you are getting date() or time() from your server using PHP, it will return server timezone. That means it will return Indian time.
So, you should change it to American timezone to get correct date() or time() from server.
You can put this in your header of footer php file to set timezone in all of your pages.
Timezone Array
If you are giving option to select timezone to user, you should list out all timezones in your select box. You can simply use this below function to do this. it will return array of timezones.
And you can use that array in your form like the above code.
0 comments:
Post a Comment