change date format from Y-m-d to d-m-Y [duplicate]

馋奶兔 提交于 2019-12-14 04:14:53

问题


based on this code :

$tarikh = mysql_real_escape_string($_POST['tarikh']);
    $tarikh = date('Y-m-d', strtotime($_POST['tarikh']));

can someone show me to convert the format from Y-m-d to d-m-Y format ? thanks


回答1:


try this

$tarikh = mysql_real_escape_string($_POST['tarikh']);
$myDateTime = DateTime::createFromFormat('Y-m-d', $tarikh);
$newDateString = $myDateTime->format('d-m-Y');


来源:https://stackoverflow.com/questions/25697016/change-date-format-from-y-m-d-to-d-m-y

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!