首页 > IT职业 > IT生活 > php时间格式转换--142
时间格式的处理
1.数据库一般保存时间戳的格式,页面显示为了简明显示为时间格式,需要对页面做一些时间格式的处理
数据库入库时时间格式的转换方法:
后台代码:
时间格式--》时间戳
//---后台MVC中的action方法(Bureaup,Bureaupinfo)为两张表
public function addbur() {
if ($this->isPost()) {
$db = M("Bureaup");
$info=M("Bureaupinfo");
$begintime = $this->_POST("begintime");
$begintime = strtotime($begintime);
$endtime = $this->_POST("endtime");
$endtime = strtotime($endtime);
if ($db->create()) {
if($db->add()){
//获取最后执行的SQL语句
$id = $db->getLastInsID();
$_POST['lll']['begintime']=$begintime;
$_POST['lll']['endtime']=$endtime;
$data=$info->add($_POST['lll']);
$this->success("添加成功!);
} else {
$this->error("添加失败!");
}
} else {
$this->error($db->getError());
}
} else {
$this->display();
}
}
//判定时间戳是否为0,为0输出格式为0000-00-00,否则输出"Y-m-d"格式。
if($k==validity){
if($dbold[$k]==0){
$dateold="0000-00-00";
}else{
$dateold=date("Y-m-d",$dbold[$k]);
}
$datenew=date("Y-m-d",$dbnew[$k]);
}
前台代码:
时间戳--》时间格式
0000-00-00
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1721/viewspace-2809749/ ,如需转载,请注明出处,否则将追究法律责任。