ITPub博客

首页 > IT职业 > IT生活 > php时间格式转换--142

php时间格式转换--142

IT生活 作者:yaoran 时间:2021-09-09 09:22:19 0 删除 编辑

时间格式的处理

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]);

}

前台代码:

时间戳--》时间格式

开始时间:{$datainfo["begintime"]|date="Y-m-d",###}

结束时间:{$datainfo["endtime"]|date="Y-m-d",###}

0000-00-00



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1721/viewspace-2809749/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: python 数据库处理
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    112
  • 访问量
    593