타임 스탬프 및 기타 정보를 기반으로 날짜를 계산하고 싶습니다. 샘플로날짜가 잘못된 날짜를주는 이유는 무엇입니까?
function getLastDeliveryDate($timestamp,$endOfMonth=true,$extraMonth=0){
$days = 0;
$extraDays = 0;
$endOfCurrentMonth = 0;
$tsDay = 86400;
if($endOfMonth){
$endOfCurrentMonth = date("t", $timestamp) - date("d",$timestamp);
//rest of days in current month. In this sample 16 days
}
for($i=0;$i<$extraMonth;$i++){
$x = $i + 1;
$date = new DateTime(date("Y-m-d", $timestamp)); //create dateobject to add a month
$date->modify("+{$x} month"); // add the month (next month)
$extraDays += date("t", strtotime($date->format("Y-m-d")));
// get the days of the selected month and add them to count
// in this case its 31 + 30 + 31 = 92
}
$days = $endOfCurrentMonth + $extraDays;
// count everything together 16 + 92 = 108 days
return date("d.m.y", $timestamp + ($tsDay*$days));
//returning date with 108 days added.
}
내가 같은 함수를 호출 : :
// the timestamp is 2015-07-15
echo getLastDeliveryDate(1436911200, true, 3);
// should return 2015-10-31
그러나이 반환 2015-10-30
을 내가 왜 모르겠
내 기능은 같다. 하지만 108 일간은 2015-10-31
입니다. 여기서 뭐가 잘못 됐니? 나는 그것의 올바른
echo getLastDeliveryDate(1436911200, true, 2);
를 호출하고
2015-09-30
이 사실 나는에 allways 원하는 나에게 달의 마지막 날을 제공하는 경우
.
는 편집 :
유선, 나는 여기를 테스트하는 경우 : IDEONE 모든 작동합니다. 그것은 당신이 루프 전에 날짜 객체를 생성 할 필요가
시간대 오프셋을 확인 하시겠습니까? – Mouser
내가 이미 전달 된 타임 스탬프에 포함되어 있더라도? 기본 날짜가 맞고 반환 된 날짜도 올바르므로 그게 아니라고 생각해보십시오. 그래서 이것은 불가능합니다 ... timbugtu에도 24 시간 모두 있습니다 : D – Dwza
정말로'$ endOfMonth'를 직접 손으로 설정합니까? ist는 무엇인가? 타임 스탬프가 해당 월의 마지막 날인지 여부를 확인하는 기계적이고 쉬운 방법이 있습니다. – ITroubs