当前位置:编程学习 > php >>

这个php程序为什么打印出来的时间是1970年,不是我的本地时间啊?

<?php class User{ public $name; private $password,$lastlogin; function __construct($name,$password){ $this->name=$name; $this->password=$password; $this->lastlogin=time(); } function getLastLogin() { return(date("M d Y", $this->lastLogin)); } } $user = new User("Leon", "sdf123"); print($user->getLastLogin()."<br/>"); ?>
答案:function getLastLogin() {
return(date("M d Y", $this->lastLogin)); // 改成   $this->lastlogin
}
其他:使用前先设置一下时区 $this->lastlogin=time();



return(date("M d Y", $this->lastLogin));



$this->lastLogin   大小写检查下。 根据我的判断   是你的new user方法里面的insert语句有问题.没有正确的插入时间
使用的是0
php的time函数传递为0的时候才是1970年1月1日
去查下吧,亲. 

上一个:PHP程序不理解
下一个:php程序员是否需要高学历?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,