我无法摆脱这个错误消息:
调用非对象上的成员函数 format()
所以,我继续谷歌搜索并找到一些好的来源,例如这个 StackOverflow 问题 https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php.
我尝试做类似的事情,但失败了。这是我的代码:
$temp = new DateTime();
/*ERROR HERE*/ $data_umat['tanggal_lahir'] = $data_umat['tanggal_lahir']->format('Y-m-d');
$data_umat['tanggal_lahir'] = $temp;
所以,我做了尝试和错误,我发现我是否这样做:
$data_umat['tanggal_lahir'] = date("Y-m-d H:i:s");
日期将成功转换,但它总是返回今天的日期(我不想要)。
我想转换日期以便10/22/2013
将2013-10-22
.
你正在调用方法format()
在非对象上。尝试这个:
$data_umat['tanggal_lahir'] = new DateTime('10/22/2013');
$data_umat['tanggal_lahir'] = $data_umat['tanggal_lahir']->format('Y-m-d');
或单行:
$data_umat['tanggal_lahir'] = date_create('10/22/2013')->format('Y-m-d');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)