src/AppBundle/Common/TimeMachine.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace AppBundle\Common;
use DateTime;
use DateTimeZone;
class TimeMachine
{
private static $mockedTime = 0;
private $timezone;
const HALF_HOUR = 1800;
const ONE_HOUR = 3600;
const ONE_DAY = 86400;
const ONE_MONTH = 259200;
/**
* 转化为 时间字符串, 如 2018-12-22 13:33:54
*
* @dataExpression strtotime 指定的第一个参数, 如 '+1 Day'
* @format 时间格式
*/
public static function expressionToStr($dateExpression, $format = 'Y-m-d H:i:s')
{
$timeMachine = new self('Asia/Shanghai');
return $timeMachine->format($format, strtotime($dateExpression));
}
public static function isTimestamp($timestamp)
{
return ((string) (int) $timestamp === (string) $timestamp)
&& ($timestamp <= PHP_INT_MAX)
&& ($timestamp >= ~PHP_INT_MAX);
}
public function __construct($timezone)
{
$this->timezone = $timezone;
}
/**
* 单元测试时,解决因为时间引起的测试报错问题
*/
public static function time()
{
return empty(self::$mockedTime) ? time() : self::$mockedTime;
}
public static function setMockedTime($time)
{
self::$mockedTime = $time;
}
public function format($format, $timestamp = null)
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。