Php 显示用户帐户年龄
我想显示我的用户注册的年龄(他们注册的时间)。 我使用这行代码显示用户控制器中的注册日期:Php 显示用户帐户年龄,php,datetime,Php,Datetime,我想显示我的用户注册的年龄(他们注册的时间)。 我使用这行代码显示用户控制器中的注册日期: $D->date_register = pstrftime($this->lang('usr_info_birthdate_dtformat'), $u->reg_date); 在HTML中: <?= $D->date_register ?> 注册日期(reg_date)是数据库中的整数(10)(unix时间戳)。我知道我必须从当前时间中减去reg_date以获
$D->date_register = pstrftime($this->lang('usr_info_birthdate_dtformat'), $u->reg_date);
在HTML中:
<?= $D->date_register ?>
注册日期(reg_date)是数据库中的整数(10)(unix时间戳)。我知道我必须从当前时间中减去reg_date以获得帐户年龄,但我不知道如何做到这一点。中概述的方法可能是最好的。只需创建两个DateTime对象,一个用于reg_date,另一个用于当前时间,对它们进行区分,然后使用生成的对象。我使用了它,出现了这个错误!致命错误:在创建对象时,使用调用非对象inTry上的成员函数diff(),而不是提供时间戳。据我所知,DateTime不喜欢构造函数中的unix时间戳$my_time_object->setTimestamp($unix_timestamp_from_database)代码>