ChronosTime 类
常量
属性摘要
-
$ticks protected
int
-
$toStringFormat protected static
string
用于 __toString 方法的格式。
方法摘要
-
__construct() public
从另一个实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的时间字符串中复制时间。
-
__toString() public
使用设置的格式将实例格式化为字符串。
-
between() public
返回时间是否在时间范围内。
-
endOfDay() public static
返回设置为一天结束的实例 - 如果
$microseconds
为真,则为 23:59:59 或 23:59:59.999999。 -
equals() public
返回时间是否等于目标时间。
-
format() public
使用与
DateTimeImmutable::format()
相同的语法格式化字符串。 -
getHours() public
返回时钟小时。
-
getMicroseconds() public
返回时钟微秒。
-
getMinutes() public
返回时钟分钟。
-
getSeconds() public
返回时钟秒。
-
greaterThan() public
返回时间是否大于目标时间。
-
greaterThanOrEquals() public
返回时间是否大于或等于目标时间。
-
lessThan() public
返回时间是否小于目标时间。
-
lessThanOrEquals() public
返回时间是否小于或等于目标时间。
-
midnight() public static
返回设置为午夜的实例。
-
mod() protected static
-
noon() public static
返回设置为正午的实例。
-
now() public static
返回设置为服务器时间的实例。
-
parse() public static
从另一个实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的字符串中复制时间。
-
parseString() protected static
-
resetToStringFormat() public static
将用于转换为字符串的格式重置为默认值。
-
setHours() public
设置时钟小时。
-
setMicroseconds() public
设置时钟微秒。
-
setMinutes() public
设置时钟分钟。
-
setSeconds() public
设置时钟秒。
-
setTime() public
设置时钟时间。
-
setToStringFormat() public static
设置转换为字符串时使用的默认格式。
-
toDateTimeImmutable() public
返回设置为此时钟时间的
DateTimeImmutable
实例。 -
toNative() public
返回设置为此时钟时间的
DateTimeImmutable
实例。
方法详细
__construct() ¶ public
__construct(Cake\Chronos\ChronosTimeDateTimeInterface|string|null $time = null, DateTimeZone|string|null $timezone = null)
从另一个实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的时间字符串中复制时间。
默认设置为服务器时间。
参数
-
Cake\Chronos\ChronosTimeDateTimeInterface|string|null
$time optional 时间
-
DateTimeZone|string|null
$timezone optional 用于现在的时区
between() ¶ public
between(Cake\Chronos\ChronosTime $start, Cake\Chronos\ChronosTime $end, bool $equals = true): bool
返回时间是否在时间范围内。
参数
-
Cake\Chronos\ChronosTime
$start 目标范围的开始
-
Cake\Chronos\ChronosTime
$end 目标范围的结束
-
bool
$equals optional 是否包含范围的开始和结束
返回
bool
endOfDay() ¶ public static
endOfDay(bool $microseconds = false): static
返回设置为一天结束的实例 - 如果 $microseconds
为真,则为 23:59:59 或 23:59:59.999999。
参数
-
bool
$microseconds optional 是否设置微秒
返回
static
equals() ¶ public
equals(Cake\Chronos\ChronosTime $target): bool
返回时间是否等于目标时间。
参数
-
Cake\Chronos\ChronosTime
$target 目标时间
返回
bool
format() ¶ public
format(string $format): string
使用与 DateTimeImmutable::format()
相同的语法格式化字符串。
由于它使用 DateTimeImmutable::format() 来格式化字符串,因此非时间格式化程序仍将被解释。请确保首先转义这些字符。
参数
-
string
$format 格式字符串
返回
string
greaterThan() ¶ public
greaterThan(Cake\Chronos\ChronosTime $target): bool
返回时间是否大于目标时间。
参数
-
Cake\Chronos\ChronosTime
$target 目标时间
返回
bool
greaterThanOrEquals() ¶ public
greaterThanOrEquals(Cake\Chronos\ChronosTime $target): bool
返回时间是否大于或等于目标时间。
参数
-
Cake\Chronos\ChronosTime
$target 目标时间
返回
bool
lessThan() ¶ public
lessThan(Cake\Chronos\ChronosTime $target): bool
返回时间是否小于目标时间。
参数
-
Cake\Chronos\ChronosTime
$target 目标时间
返回
bool
lessThanOrEquals() ¶ public
lessThanOrEquals(Cake\Chronos\ChronosTime $target): bool
返回时间是否小于或等于目标时间。
参数
-
Cake\Chronos\ChronosTime
$target 目标时间
返回
bool
now() ¶ public static
now(DateTimeZone|string|null $timezone = null): static
返回设置为服务器时间的实例。
参数
-
DateTimeZone|string|null
$timezone optional 用于现在的时区
返回
static
parse() ¶ public static
parse(Cake\Chronos\ChronosTimeDateTimeInterface|string $time = null, DateTimeZone|string|null $timezone = null): static
从另一个实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的字符串中复制时间。
默认设置为服务器时间。
参数
-
Cake\Chronos\ChronosTimeDateTimeInterface|string
$time 可选 时间
-
DateTimeZone|string|null
$timezone optional 用于现在的时区
返回
static
parseString() ¶ protected static
parseString(string $time): int
参数
-
string
$time 格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的时间字符串
返回
int
setMicroseconds() ¶ public
setMicroseconds(int $microseconds): static
设置时钟微秒。
参数
-
int
$microseconds 时钟微秒
返回
static
setTime() ¶ public
setTime(int $hours = 0, int $minutes = 0, int $seconds = 0, int $microseconds = 0): static
设置时钟时间。
参数
-
int
$hours 可选 时钟小时
-
int
$minutes 可选 时钟分钟
-
int
$seconds 可选 时钟秒
-
int
$microseconds 可选 时钟微秒
返回
static
setToStringFormat() ¶ public static
setToStringFormat(string $format): void
设置转换为字符串时使用的默认格式。
参数
-
string
$format 将来 __toString() 调用中使用的格式。
返回
void
toDateTimeImmutable() ¶ public
toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable
返回设置为此时钟时间的 DateTimeImmutable
实例。
参数
-
DateTimeZone|string|null
$timezone optional DateTimeImmutable 实例所在的时区
返回
DateTimeImmutable
toNative() ¶ public
toNative(DateTimeZone|string|null $timezone = null): DateTimeImmutable
返回设置为此时钟时间的 DateTimeImmutable
实例。
toDateTimeImmutable()
的别名。
参数
-
DateTimeZone|string|null
$timezone optional DateTimeImmutable 实例所在的时区
返回
DateTimeImmutable