我需要处理六月的最后一个月。我怎样才能做到这一点呢?假设今天是 2014年9月1日,我需要相对地处理 2014年6月1日。
$dt = new DateTime('01-09-2014', new DateTimeZone('UTC'));
$dt->modify('June last year');
echo $dt->format('d F Y');
But It give me 01 June 2013 and not 01 June 2014
有什么想法吗?
编辑>>>
如果我在{July, Aug, Sep,…12} 2014 ===我需要地址 2014年6月01日
如果我在{Jan, Feb, Mar, Apr, May} 2015 ===我需要地址01 June 2014
不能使用php代码。只有"相对日期字符串"
如果您只需要php datetime Relative Formats
的解决方案,我认为这对于Relative Formats
的功能逻辑是不可能的。
//回答问题前编辑
像这样的东西' ?
$dt = new DateTime('01-09-2014', new DateTimeZone('UTC'));
if( date('n') >= 6 )
{
// last year june
$dt->modify('June last year');
} else {
// current year june
$dt->modify('June this year');
}
echo $dt->format('d F Y');
$dt = new DateTime ( '01-04-2014', new DateTimeZone ( 'UTC' ) );
$dt->modify ( ($dt->format ( 'm' ) < 6) ? 'June last year' : 'June this year' );
echo $dt->format ( 'd F Y' );