简体   繁体   中英

PHP date is one day ahead?

when I write <?php echo date('d'); ?> <?php echo date('d'); ?> the day is always one day ahead? I've checked everything and it doesn't echo that on my other websites on the same database

Try setting the timezone to one of these values .

For example, try this at the start of your script (with the appropriate timezone, of course):

<?php date_default_timezone_set('Pacific/Auckland'); ?>

You need to set date_default_timezone_set() . Your server time is one day different from where you actually are.

http://php.net/manual/en/function.date-default-timezone-set.php

The database may be the same, but the server is most likely different. The date is pulled from the hosting server.

A quick fix is to set date_default_timezone_set()

Your other option, if you are hosting your own site, is to fix the date time settings on the server itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM