2016-12-13 78 views
1

大家好我正在處理顯示錯誤時間的php腳本。PHP返回兩次不同的時間

我使用的功能是:

<?php 
    echo "The time is " . date("h:i:sa"); 
?> 

,顯示我的時間加上6個小時。

但是當我使用<?php echo exec('date'); ?>

它顯示了正確的時間。

它設置在godaddy上的專用VPS上。 WHM中的服務器時間設置爲-6或America/Central。

我使用第一個函數從wordpress中的自定義文章類型中拉出一個自定義字段,顯示學校的上學日期問題是,當時鐘不在6小時時,它顯示錯誤的上課時間爲12小時a一天(6小時錯誤,12小時正確,6小時再次錯誤)。

我試着在PHP.ini和.htaccess中設置它。 WTF?整個小部件代碼看起來像這樣。

<?php 

$current_day = date('Ymd'); 
// args 
$args = array(
    'posts_per_page' => 1, 
    'post_type' => 'schoolday', 
     'date_query' => array(
     array(
      'year' => $today["year"], 
      'month' => $today["mon"], 
      'day' => $today["mday"], 
     ), 
    ) 
); 

// get results 
$the_query = new WP_Query($args); 

// The Loop 
?> 
<div class="one-half first"><time datetime="<?php echo date("Y-m-d");?>" class="icon"> 

    <strong>School Day</strong> 
    <span><?php if($the_query->have_posts()): ?> 
     <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> 
        <?php the_field('realschoolday'); ?></span> 
</time></div><?php endwhile; ?><?php endif; ?> 

<div class="one-half"><time datetime="<?php echo date("Y-m-d");?>" class="icon"> 
    <em><?php echo date('l'); ?></em> 
    <strong><?php echo date('F'); ?></strong> 
    <span><?php echo date('jS'); ?></span> 
</time></div> 

<?php 
    echo "The time is " . date("h:i:sa"); 
?> 
<br /> 
<?php echo exec('date'); ?>` 

我添加了最後一行故障排除,它回聲'正確的時間。什麼#$%#。

I「m,在PHP超新,所以請善待。

+0

date.timezone在你的php.ini中 – mkaatman

+3

'date(「h:i:sa」);'依賴於php內部時間,'exec('date');'調用系統時間低於該腳本 – JOUM

+0

謝謝服務器支持團隊不知道它們之間的區別,我如何調整php的內部時間?我已經將它設置在WHM中,然後嘗試.htacess和php.in一世。非常感謝你。 –

回答