<?php
class DatetimeTool {
public function now(string $formato_final = 'Y-m-d H:i:s'){
return (new DateTime('now'))->format($formato_final);
}
public function format(string $data, string $formato_final){
return (new DateTime($data))->format($formato_final);
}
public function add(string $data_inicio, array $add = [0,0,0,0,0,0], string $formato_final){
return (new DateTime($data_inicio))->add(new DateInterval('P'.$add[0].'Y'.$add[1].'M'.$add[2].'DT'.$add[3].'H'.$add[4].'M'.$add[5].'S'))->format($formato_final);
}
public function sub(string $data_inicio, array $add = [0,0,0,0,0,0], string $formato_final){
return (new DateTime($data_inicio))->sub(new DateInterval('P'.$add[0].'Y'.$add[1].'M'.$add[2].'DT'.$add[3].'H'.$add[4].'M'.$add[5].'S'))->format($formato_final);
}
}
?>
<?php
var_dump((new DatetimeTool)->now('d-m-Y'));
var_dump((new DatetimeTool)->format('1970-01-01', 'd-m-Y'));
var_dump((new DatetimeTool)->add(date('d-m-Y H:i:s'), [0,1,0,0,10,0], 'd-m-Y'));
var_dump((new DatetimeTool)->sub(date('d-m-Y H:i:s'), [0,1,0,0,10,0], 'd-m-Y'));
?>