| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- /**
- * 描述.
- *
- * @author nj <nj@gmail.com>
- * @date 2019-11-04 18:43:48
- */
- declare(strict_types=1);
- /**
- * 转换至mongoISODate格式.
- * @param mixed $date 任意有效的时间格式.
- * @param mixed $tz 时区
- * @return string|null
- */
- function toMongoIsoDate($date, $tz = null)
- {
- if (empty($tz)) {
- $tz = env('APP_TIMEZONE', null);
- }
- $millSecond = \Carbon\Carbon::parse($date)->timestamp * 1000;
- $isoDateObj = new MongoDB\BSON\UTCDateTime($millSecond);
- $isoDate = $isoDateObj->toDateTime()->setTimezone(new DateTimeZone($tz));
- return $isoDateObj;
- }
- /**
- * mongoIso时间转CarbonTime时间
- * @param \MongoDB\BSON\UTCDateTime $utcDate
- * @return \Carbon\Carbon
- */
- function mongoIsoDateToCarbonTime(\MongoDB\BSON\UTCDateTime $utcDate)
- {
- return \Carbon\Carbon::parse($utcDate->toDateTime()->setTimezone(new DateTimeZone(env('APP_TIMEZONE'))));
- }
|