laravel 2020-01-01T00:00:00.000000Z 日期转化

本文解释了UTC世界标准时间和北京时间的关系,通过示例说明如何将北京时间转化为国际标准时间(UTC+8)。并提供一个代码片段,展示如何在模型中实现日期格式的标准化输出。

解释
T表示分隔符,Z表示的是UTC。
UTC:世界标准时间,在标准时间上加上8小时,即东八区时间,也就是北京时间。

举例

北京时间:2020-01-14 00:00:00对应的国际标准时间格式为:2020-01-13T16:00:00.000Z

解决方案
模型中添加以下方法即可

    protected function serializeDate(\DateTimeInterface $date)
{
    return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
}

 

 

ValueError: failed to prevent overwriting existing key calendar in attrs on variable 'time'. This is probably an encoding field used by xarray to describe how a variable is serialized. To proceed, remove this key from the variable's attributes manually. Raised while encoding variable 'time' with value <xarray.IndexVariable 'time' (time: 30)> Size: 240B array(['1960-08-01T00:00:00.000000000', '1962-07-01T00:00:00.000000000', '1964-06-01T00:00:00.000000000', '1966-04-01T00:00:00.000000000', '1968-03-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000', '1971-10-01T00:00:00.000000000', '1973-09-01T00:00:00.000000000', '1975-08-01T00:00:00.000000000', '1977-06-01T00:00:00.000000000', '1979-04-01T00:00:00.000000000', '1981-03-01T00:00:00.000000000', '1983-02-01T00:00:00.000000000', '1985-01-01T00:00:00.000000000', '1987-01-01T00:00:00.000000000', '1988-10-01T00:00:00.000000000', '1990-09-01T00:00:00.000000000', '1992-09-01T00:00:00.000000000', '1994-08-01T00:00:00.000000000', '1996-07-01T00:00:00.000000000', '1998-06-01T00:00:00.000000000', '2000-04-01T00:00:00.000000000', '2002-03-01T00:00:00.000000000', '2004-02-01T00:00:00.000000000', '2006-01-01T00:00:00.000000000', '2008-01-01T00:00:00.000000000', '2009-10-01T00:00:00.000000000', '2011-10-01T00:00:00.000000000', '2013-09-01T00:00:00.000000000', '2015-07-01T00:00:00.000000000'], dtype='datetime64[ns]') Attributes: standard_name: time axis: T calendar: standard note: Time represents the first day of the referenced month (e....
09-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值