THIẾT LẬP TIME ZONE TRONG PHP

I"m trying to lớn change the mặc định PHP timezone to lớn Asia/Calcutta by accessing the /etc/php5/cli/php.ini file và changing

; Defines the default timezone used by the date functions; http://php.net/date.timezone;date.timezone =to

; Defines the mặc định timezone used by the date functions; http://php.net/date.timezonedate.timezone = "Asia/Calcutta"However, when I try to lớn view current timezone under phpinfo(), the timezone follows the Europe/Berlin timezone.

I have tried stopping and restarting the Apache server, but that didn"t seem to lớn have changed the settings.

Is there something I"m missing in the process?

PS: I"m using PHP 5.6.8 currently under XAMPP.Bạn đã xem: Setting the timezone for php in the php

php datetime nói qua Improve this question Follow asked Aug 26 "15 at 10:46

Manas ChaturvediManas Chaturvedi 3,9501414 gold badges4141 silver badges9494 bronze badges 4 add a bình luận |

8 Answers 8

Active Oldest Votes27I tried all the other possible solutions posted, but none of them helped. This is what helped me save my timezone settings:

1) Go khổng lồ your phpinfo() page and tìm kiếm for Loaded Configuration file and open the php.ini file mentioned under that section.

Bạn đang xem: Thiết lập time zone trong php

2) Change the mặc định timezone settings by adding your new timezone by modifying this line: date.timezone=Asia/Kolkata.

3) Save the php.ini file & stop the Apache server.

4) Restart the Apache server. The timezone settings should now be modified.

cốt truyện Improve this answer Follow answered Aug 26 "15 at 12:43

Manas ChaturvediManas Chaturvedi 3,9501414 gold badges4141 silver badges9494 bronze badges 1 địa chỉ a phản hồi | 9You are changing the wrong file. The tệp tin /etc/php5/cli/php.ini is used by cli - command line interface. Don"t forget lớn reboot your web-server after you update the right one: sudo service apache2 restart or sudo service php5-fpm restart

File locations for different OS:

OS -> Locationwindows(With Xampp Installation) -> /xampp/php/php.in Mac OSX -> /private/etc/php.iniLinux -> /etc/php.ini -> /usr/bin/php5/bin/php.ini -> /etc/php/php.ini -> /etc/php5/apache2/php.ini chia sẻ Improve this answer Follow answered Aug 26 "15 at 10:53

*

millermiller 82488 silver badges1515 bronze badges 4 showroom a phản hồi | 8You can change it in the code without touching the ini file, at the beginning of your code add:

date_default_timezone_set("Asia/Calcutta") nội dung Improve this answer Follow answered Aug 26 "15 at 10:51

*

Daniel KromDaniel Krom 8,51733 gold badges3636 silver badges3939 bronze badges 4 địa chỉ a bình luận | 1If you "re serious about web developping get a VM going(Virtual Box + Vagrant). With XAMPP be careful. Sometimes there"s more than 1 php.ini file và you might be editing the wrong one. To edit the real one, access it from the XAMPP control panel.You can use the a function in your code: date_default_timezone_set(); giới thiệu Improve this answer Follow answered Aug 26 "15 at 10:53
*

PatrickPatrick 18511 silver badge99 bronze badges showroom a phản hồi | 1I had the same problem and discovered that there are two date.timezone statements in php.ini in my version of XAMPP out of the box. The first statement one is commented out, but the second one is set lớn Europe/Berlin. So you if you edit your php.ini and tìm kiếm for timezone & logically uncomment the first statement with your time zone, the second statement overrides that back khổng lồ Europe/Berlin.

mô tả Improve this answer Follow answered Feb 5 "19 at 0:17 Shane SkidmoreShane Skidmore 1111 bronze badge địa chỉ cửa hàng a phản hồi | 0Check configuration in your system.

In my case, it was "Ubuntu"

My case Laravel 6. Edit /config/app.php file & change this line

"timezone" => "UTC",to

"timezone" => env("APP_TIMEZONE", "UTC"),then edit .env file. địa chỉ your timezone (timezone list)

APP_TIMEZONE="America/New_York"clear configurations

php artisan config:clear cốt truyện Improve this answer Follow answered Feb 21 at 15:33 namalnamal 40255 silver badges1111 bronze badges địa chỉ cửa hàng a phản hồi | -1In my case,there were two "date.timezone=".

Xem thêm: Cách Làm Lẩu Nướng Ngon - Cách Làm Lẩu Nướng Thơm Lừng, Hấp Dẫn

Maybe you should correct both of them.

Just using Ctrl+F và input "date.timezone" , you should find another one.

chia sẻ Improve this answer Follow answered Feb 24 at 18:23 Tatsuhiko MizunoTatsuhiko Mizuno 1 địa chỉ cửa hàng a comment |

Your Answer

Thanks for contributing an answer to lớn Stack Overflow!

Please be sure lớn answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft savedDraft discarded

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using e-mail and Password Submit

Post as a guest

Name email Required, but never shown

Post as a guest

Name email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree lớn our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged php datetime or ask your own question.

The Overflow Blog Featured on Meta Linked0Date function time in hour always returning 1 php11Wrong PHP date() output đầu ra in wamp server0Yii2: Setting timezone1PHP my timezone is no setting up in PHP.ini file in xampp0timestamp in server giving wrong time even after setting timezone in php0PHP new DateTime() throws Invalid date.timezone value0PHP date_default_timezone_set() not returning expected results0Change timezone in shopware 6?1How khổng lồ fix date format in PHP Codeigniter Related 2773 How can I prevent SQL injection in PHP? 2699 Deleting an element from an array in PHP 4680 Reference — What does this symbol mean in PHP? 2565 Why shouldn't I use mysql_* functions in PHP? 3 Symfony php.ini Debian 0 Php Info shows Incorrect mặc định timezone as UTC 1 PHP my timezone is no setting up in PHP.ini tệp tin in xampp Hot Network Questions more hot questions

Question feed Subscribe lớn RSS Question feed to subscribe lớn this RSS feed, copy and paste this URL into your RSS reader.