이상한 문제가 여기에 있습니다.strtotime ("next march")
나는 3 월에 오는 날짜를 잡으려고 노력하고 있지만 제대로 작동하지 않는 것 같습니다.
$nextMarch = strtotime("next march");
이 작은 코드는 무엇이 잘못 되었을까요?
Timestamp of nearest valid month
이상한 문제가 여기에 있습니다.strtotime ("next march")
나는 3 월에 오는 날짜를 잡으려고 노력하고 있지만 제대로 작동하지 않는 것 같습니다.
$nextMarch = strtotime("next march");
이 작은 코드는 무엇이 잘못 되었을까요?
Timestamp of nearest valid month
strtotime
다른 (및/또는 추가) 정보를 제공해야한다고 생각합니다.
$nextMarch = strtotime("1 march");
var_dump($nextMarch, date('Y-m-d H:i:s', $nextMarch));
하지만 당신은 얻을 올해 행진 있습니다 : 예를 들어
는, 일의 수는 3 월하려면 "다음"행진, 예를 얻기 위해, 그래서int 1235862000
string '2009-03-01 00:00:00' (length=19)
내년 :
$nextMarch = strtotime("1 march +1 year");
var_dump($nextMarch, date('Y-m-d H:i:s', $nextMarch));
그리고 당신은 얻을 :
,int 1267398000
string '2010-03-01 00:00:00' (length=19)
그래서 올해 나 다음번 중 어느 것이 좋을지 알고 싶다면 직접 계산해야 할 것입니다.
- (... 심지어 간단한 해결책은 확실히 좋은 것입니다하지만 난 정말이 생각처럼하지 않습니다, 그러나 그것은 작동하는 것 같군)$nextMarch = strtotime("1 march");
if ($nextMarch < time()) {
$nextMarch = strtotime("1 march +1 year");
}
var_dump($nextMarch, date('Y-m-d H:i:s', $nextMarch));
: 이런 식으로 뭔가 트릭을 할 수 있습니다
'오는 3 월의'날짜는 무엇입니까? 3 월은 31 일 (각 날에 하나씩)의 모음입니다.
어쨌든, (온라인 매뉴얼에서) this example of strtotime() 그것은 좀 가치가있을 수도
"현재 달의 마지막 날을 '반환'다음 달 '사용합니다.
좀 더 자신을 엉망으로하고, strtotime으로 덜 의존 할 의향이 될 것입니다 :
$thisYear = date("Y");
$nextYear = $thisYear + 1;
$nextMarch = date($yourFormat, strtotime("March 1, $nextYear"));
strtotime으로 여기에 사용하는 것은 조금 이상한 나에 대한 이상한 것 같다. 이렇게하려면 mktime을 사용하는 것이 좋습니다.
mktime (0,0,0,3,1,date("Y")+1);
나는 여기에 무슨 짓을했는지, 다른 프로젝트에 비슷한 일을해야했다 :
function getNextMarch($timestamp) {
$fields = array();
$fields['timestamp'] = $timestamp;
$fields['unixtime'] = strtotime($timestamp);
$fields['current_month'] = date("m", $fields['unixtime']);
$fields['end_date_pre'] = new DateTime($fields['timestamp']);
switch ($fields['current_month']) {
case 4 :
$return = 11;
break;
case 5 :
$return = 10;
break;
case 6 :
$return = 9;
break;
case 7 :
$return = 8;
break;
case 8 :
$return = 7;
break;
case 9 :
$return = 6;
break;
case 10 :
$return = 5;
break;
case 11 :
$return = 4;
break;
case 12 :
$return = 3;
break;
case 1 :
$return = 2;
break;
case 2 :
$return = 1;
break;
case 3 :
$return = 0;
break;
}
$fields['str'] = $return . ' months';
if ($return > 1) {
$fields['str'] = $return . ' month';
}
date_add($fields['end_date_pre'], date_interval_create_from_date_string($fields['str']));
return $fields['end_date_post'] = $fields['end_date_pre']->format('Y-m-d G:i:s');
}
두 질문 : (1) 어떤 *이 모두에 중요하다 (점점 *입니다 "예기치 않은 행동"질문)? (2) 어떤 PHP 버전입니까? – paxdiablo
(1) 나는 아무것도 얻지 못하고있다. 오류 없음. 빈 결과 만 나타납니다. 부울 거짓을 반환하는 것 같아요. (2) PHP 5.3.0 – Nirmal