2017-04-02 17 views
1
function test() 
{ 
    echo time(); 
    echo "<hr>"; 
    echo $this->get_date(time()); 
} 

和另一功能時間()函數(FY的升JS 一個噸G:I:S A)格式

function get_date($timestamp) 
{ 
    $the_date = date('l jS \of F Y \a\t G:i:s A', $timestamp); 
    return $the_date; 
} 

當我使用的測試功能的時間()函數提供了一個有效的結果,但生成的時間戳是關閉了2小時 例如。如果時間()是1491118740,那麼時間戳格式應該是2017年4月2日星期日上午7:39:00,但我將在2017年4月2日星期日上午9:39:00獲取如何解決此問題?請幫助..並提前致謝... PS。檢查時間戳值,你可以使用本網站使用date_default_timezone_set()

示例腳本使用http://www.unixtimestamp.com/index.php

+0

結賬,如果有時差 – hassan

回答

1

更新時區:

// check your default timezone first 
echo date_default_timezone_get(); 

// change the timezone: I use 'Africa/Lagos' for example 
date_default_timezone_set('Africa/Lagos'); 

// make sure it's changed 
echo date_default_timezone_get(); 

// now use your function 
echo date('l jS \of F Y \a\t G:i:s A'); 

進一步閱讀here

+0

謝謝它似乎我的默認時區設置爲其他地方而不是UTC – lazyme114