2016-08-02 2 views
0

다음을 설정하면 time()이 영국 서머 타임의 기본 시간을 반환하지만 대신 UTC/GMT를 얻습니다.time() 일광 절약 시간 값을 반환하지 않습니다.

date_default_timezone_set("Europe/London"); 

나는 BST 조정 데이터베이스에 저장된 값이 시간()에서 반환 된 값을 비교해야합니다. 시차가 있기 때문에 현재 시스템이 예상대로 작동하지 않습니다. time() 함수가 BST 시간을 반환해야하거나 런던이 BST에 있는지 감지하여 time()에서 결과에 3600을 더할 수있는 방법이 필요합니다. 두 가지 해결책 모두 환영받을 것입니다.

date_default_timezone_set("Europe/London"); 

// Wordpress - Getting a value from the DB 
$min_deadline = get_post_meta($id,'wdm_deadline_min',true); 

$min_signup_check = false; 
if (!empty($min_deadline) && time() >= strtotime($min_deadline)) 
    $min_signup_check = true; 
+2

그건 어떻게'time()'이 작동하는지입니다. 대신 DateTime 개체 사용 – apokryfos

+0

일광 절약 시간으로 인한 성가신 문제는 끝이없는 것 같습니다. –

+1

@JeffPuckettII 일광 절약 시간은 인위적 빛을 선행하는 구식 개념입니다. 문제를 일으키는 것은 여기에 있습니다. – apokryfos

답변

0

GMT와 BST 사이에 차이가있을 경우 getoffset을 사용하여 아래의 두 가지 방법을 찾았습니다.

function getOffset($tzId, $time = null) { 
    if($time == null){ 
     $time = gmdate('U'); 
    } 

    $tz = new DateTimeZone($tzId); 

    $transition = $tz->getTransitions($time); 

    return $transition[0]['offset']; 
} 

function getDST($tzId, $time = null) { 
    if($time == null){ 
     $time = gmdate('U'); 
    } 

    $tz = new DateTimeZone($tzId); 

    $transition = $tz->getTransitions($time); 

    return $transition[0]['isdst']; 
}