1. Carbon

文档链接:: http://carbon.nesbot.com/docs/

1.1. 时区处理

// 转换 GMT+11的时间为上海时间
Carbon::parse('2018-05-30',env("MTSERVER_DEMO_TIMEZONE","GMT+11"))
                                ->timezone(env("APP_TIMEZONE",'Asia/Shanghai'))->format('Y-m-d H:i:s');

1.2. 时间周期计算

setlocale(LC_ALL, array('zh_CN.UTF-8', 'zh_CN.utf8', 'zh_CN'));
            $translator = Carbon::getTranslator();
            $translator->setMessages('zh_CN', array(
                'year'  => ':count年',
                'month' => ':count个月',
                'day'   => ':count天',
                'hour'  => ':count小时',
                'minute' => ':count分钟',
                'second' => ':count秒',
            ));
            Carbon::setLocale('zh_CN');
            $cycle = Carbon::parse('2018-06-05 10:01:09')
                ->diffForHumans(Carbon::parse(""), true, false, 6);
     //23小时 31分钟 26秒

results matching ""

    No results matching ""