PHP:将YYYY-MM-DD转换为DD-MM-YYYY? [重复]

This question already has an answer here:

Yes, I know there are a lots of other topics about it, but my problem is here:

I only can use

date_format(new DateTime($ymd_date_from_db), “d.m.Y H:i:s“

when I set the timezone in my php. but I dont want to set it, because there is no need for timezone, because the timestamp value is already in $ymd_date_from_db - so i dont want to set timezone in php in addition to that. also date(....) does not work:

"It is not safe to rely on the system's timezone settings "

  • same problem , it wants me to set timezone in php.

Are there other solutions?

</div>

Try using strtotime():

date("d-m-Y", strtotime($originalDate));

Try using the format method

<?php
    $date = new DateTime($ymd_date_from_db);
    echo $date->format('d-m-Y');
?>

DateTime::format() e.g:

$DateTimeObj->format('your format')