怎么使用PHP内置对象DateTime

浏览:774 发布日期:2020/04/06 分类:ThinkPHP5专区
我是用5.1,以下代码会报错:
致命错误: Class 'app\index\controller\DateTime' not found<?php
namespace app\index\controller;

class Index extends Base {
    public function index() {

        $now = time();
        $expire = 30; //设置该policy超时时间是10s. 即这个policy过了这个有效时间,将不能访问。
        $end = $now + $expire;
        $expiration = $this->gmt_iso8601($end);

        return $this->fetch('index');
    }

    public function gmt_iso8601($time) {
        $dtStr = date("c", $time);
        $mydatetime = new \DateTime($dtStr);
        $expiration = $mydatetime->format(DateTime::ISO8601);
        $pos = strpos($expiration, '+');
        $expiration = substr($expiration, 0, $pos);
        return $expiration . "Z";
    }
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>