简体   繁体   中英

how to obtain same date result on different servers

<?php

//                            viper-7            phpfiddle
fdate(1346976000);       // Fri 2012-09-07     Thu 2012-09-06
fdate(1348704000);       // Thu 2012-09-27     Wed 2012-09-26
fdate(time());           // see yourself

function fDate($what){echo date('D Y-m-d',$what).'<br>';}

?>

test links
http://codepad.viper-7.com/d4tUES
http://www.phpfiddle.org/main/code/zdx-u10

What do I need to set up in order to have the same results on any server?
Thanks

I am sure is a matter of time zone, but I do not know how to be aware of this.

use gmdate to return gmt time

function fDate($what){echo gmdate('D Y-m-d',$what).'<br>';}

see if you still have issues.

Set the default timezone

Set it to UTC or GMT and you can use it as a basis for all your servers

date_default_timezone_set('UTC'); 

fdate(time());  // will return the UTC time

Include date_default_timezone_set at the beginning of your script based on your desired timezone.

<?php
date_default_timezone_set('America/Los_Angeles');
?>

List of Supported Timezones

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