2012-06-18 3 views
2

date('m/d/Y', strtotime('-1.5 years')) 오늘은 (2012 년 6 월 18 일) 06/18/2017으로 반환됩니다.strtotime은 분수를 처리 할 수 ​​있습니까?

왜 그런가요? 그리고 소수점 이하 자리를 처리하기 위해 strtotime을 얻는 방법이 있습니까? "-1.5"에서 "+5"로 변경되는 것 같습니다.

편집 : PHP 5.1에서 제공되므로 새로운 날짜 기능을 사용할 수 없습니다.

답변

4

가장 좋은 해결책은 몇 개월로 변환하는 것입니다. 따라서 1.5 years18 months이됩니다.

+0

그래, 그냥 바닥 ($ years * 12) 또는 그와 비슷한 것으로 생각했습니다. 아직도 궁금 해서요, 왜 깨지십니까? – Andrew

+0

'use months'도 쓰고 있습니다. – Brian

2

버그보고 https://bugs.php.net/bug.php?id=62353&edit=3이이 문제로 인해 열렸습니다.

모든 시간 기능을 포함하는 timelib이라는 라이브러리가 있습니다. 상대 시간을 시간 소인으로 변환하는 데 문제가있는 것처럼 보입니다. ,

echo strtotime("1.5 days ago"); 

-5 일 속으로 -5 :

static void timelib_set_relative(char **ptr, timelib_sll amount, int behavior, Scanner *s) 
{ 
    const timelib_relunit* relunit; 

    if (!(relunit = timelib_lookup_relunit(ptr))) { 
      return; 
    } 

    switch (relunit->unit) { 
      case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break; 
      case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break; 
      case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break; 
      case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break; 
      case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break; 
      case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break; 

      case TIMELIB_WEEKDAY: 
        TIMELIB_HAVE_WEEKDAY_RELATIVE(); 
        TIMELIB_UNHAVE_TIME(); 
        s->time->relative.d += (amount > 0 ? amount - 1 : amount) * 7; 
        s->time->relative.weekday = relunit->multiplier; 
        s->time->relative.weekday_behavior = behavior; 
        break; 

      case TIMELIB_SPECIAL: 
        TIMELIB_HAVE_SPECIAL_RELATIVE(); 
        TIMELIB_UNHAVE_TIME(); 
        s->time->relative.special.type = relunit->multiplier; 
        s->time->relative.special.amount = amount; 
    } 
} 

참고 :이 버그도 회전 같은 문제가 발생

다음 상대 시간을 만드는 함수이고 1 시간 12 시간 (상대) 대신 1 시간.

+0

달콤한! 고맙습니다. – Andrew

관련 문제