如何解决如何在Laravel中使用PHP将ISO 8601“ 20200823T203851.000Z”转换为可读的日期和时间格式?
我想使用Laravel控制器中的PHP将"20200823T203851.000Z"
日期格式转换为可读格式。我尝试了date()
,结果返回了"20200823UTC203851.0000"
,strtotime()
似乎不起作用。
public function index() {
$allCards = $this->getCardInfo();
$clanInfo = $this->getClanInfo();
$dateTime = $clanInfo->memberList[0]->lastSeen;
//data stored on dateTime = '20200823T203851.000Z'
//Required in readable format
return view( 'claninfo',compact( ['allCards','clanInfo'] ) );
}
解决方法
您可以使用Carbon
进行操作,请从here签出。
现在让我们$dateTime
可读:
public function index() {
$allCards = $this->getCardInfo();
$clanInfo = $this->getClanInfo();
$dateTime = $clanInfo->memberList[0]->lastSeen;
//data stored on dateTime = '20200823T203851.000Z'
//Required in readable format
// here is the change:
$dateTime = \Carbon\Carbon::parse($dateTime)->format('g:i a l jS F Y')
// now $dateTime will be something like this: 7:30 pm Monday 24th August 2020
return view( 'claninfo',compact( ['allCards','clanInfo'] ) );
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。