$date1 = $date2 = new DateTime();
$date2->add(new DateInterval('P3Y'));
Now $date1
and $date2
contain the same date -- three years from now. I'd like to create two separate datetimes, one which is parsed from a string and one with three years added to it. Currently I've hacked it up like this:
$date2 = new DateTime($date1->format(DateTime::ISO8601));
but that seems like a horrendous hack. Is there a "correct" way to deep copy a DateTime object?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…