栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

PHP日期格式/ Date(1365004652303-0500)/

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP日期格式/ Date(1365004652303-0500)/

首先,您需要了解自己的格式

/Date(1365004652303-0500)/

那你有

  • 时间戳(U)= 1365004652
  • 毫秒(u)= 303
  • 与格林威治时间(GMT)的差(O)= -0500

建立格式

$date = '/Date(1365004652303-0500)/';preg_match('/(d{10})(d{3})([+-]d{4})/', $date, $matches);$dt = DateTime::createFromFormat("U.u.O",vsprintf('%2$s.%3$s.%4$s', $matches));echo $dt->format('r');

输出量

Wed, 03 Apr 2013 15:57:32 -0500      ^      |= Can you see the GMT ?

interface DateFormatParser{        public function parse($string);}abstract class PregDateParser implements DateFormatParser{    protected $pattern, $format, $mask;    public function parse($string) {        $string = (string)$string;        $pattern = $this->pattern;        $format  = $this->format;        $mask    = $this->mask;        $r = preg_match($pattern, $string, $matches);        if (!$r) { throw new UnexpectedValueException('Preg Regex Pattern failed.');        }        $buffer = vsprintf($mask, $matches);        $result = DateTime::createFromFormat($format, $buffer);        if (!$result) { throw new UnexpectedValueException(sprintf('Failed To Create from Format "%s" for "%s".', $format, $buffer));        }        return $result;    }}class JsonTimestampWithOffsetParser extends PregDateParser{    protected $pattern = '/^/Date((d{10})(d{3})([+-]d{4}))/$/';    protected $format  = 'U.u.O';    protected $mask    = '%2$s.%3$s.%4$s';}$date   = '/Date(1365004652303-0500)/';$parser = new JsonTimestampWithOffsetParser;$dt     = $parser->parse($date);echo $dt->format('r');


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/435330.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号