class TimeHelper

时间相关操作

Methods

static int
gmTime()

标准的UNIX时间戳 获得当前格林威治时间的时间戳

static bool
isDate(string $date, string $sep = '-')

检测是否是标准时间

static bool
isDateRange($range)

是否是日期范围

static bool|string
datetime(int|string $time = 0, string $format = '3-3')

格式化时间

static string
time2string(mixed $second, bool $more = false)

自定义函数:time2string($second) 输入秒数换算成多少天/多少小时/多少分/多少秒的字符串

static bool|int|string
gmStr2Time(string $str)

转换字符串形式的时间表达式为GMT时间戳

static float|string
serverTimezone()

获得服务器的时区

static string
dayStart(string $date = '')

一天的开始, 未传值代表今天

static string
dayEnd(string $date = '')

一天的结束, 未传值代表今天

static string
format(int|string $time = 0, string $format = 'Y-m-d H:i')

格式化日期

static bool
isEmpty(string $date)

空日期检测

static int
datetimeToTimestamp(string $datetime)

datetime to timestamp

static string
timestampToDatetime(string $timestamp)

时间戳转换成 datetime 类型

static int|string
todayStart(bool|false $unix = false) deprecated

获取今日起始时间

static int|string
todayEnd(bool|false $unix = false) deprecated

获取今日起始时间

static false|string
tranTime(mixed $time)

精确时间间隔函数 $time 发布时间 如 1356973323 $str 输出格式 如 Y-m-d H:i:s 半年的秒数为15552000,1年为31104000,此处用半年的时间

static string
timeSince(string|int $datetime)

Returns a human readable time difference from the value to the current time. Eg: 10 minutes ago

static string
timeTense(mixed $datetime)

Returns 24-hour time and the day using the grammatical tense of the current time. Eg: Today at 12:49, Yesterday at 4:00 or 18 Sep 2015 at 14:33.

static Carbon|null
makeCarbon(Carbon|DateTime|string|int $value)

Converts mixed inputs to a Carbon object.

static string
momentFormat(string $format)

Converts a PHP date format to "Moment.js" format.

static string
micro()

返回微秒数值

static string
fetchFormat(Carbon|null|string $carbon, string $format = 'Y-m-d H:i:s')

通过 Carbon 对象来获取格式化的时间

static array
week(string $date, int $start = Carbon::MONDAY)

根据日期返回每年的周数 例如 2020-01-01 会返回 [2019,52] 周, 用于统计部分

Details

at line 21
static int gmTime()

标准的UNIX时间戳 获得当前格林威治时间的时间戳

Return Value

int

at line 32
static bool isDate(string $date, string $sep = '-')

检测是否是标准时间

Parameters

string $date date
string $sep sep

Return Value

bool

at line 56
static bool isDateRange($range)

是否是日期范围

Parameters

$range

Return Value

bool

at line 70
static bool|string datetime(int|string $time = 0, string $format = '3-3')

格式化时间

Parameters

int|string $time time
string $format format

Return Value

bool|string

at line 109
static string time2string(mixed $second, bool $more = false)

自定义函数:time2string($second) 输入秒数换算成多少天/多少小时/多少分/多少秒的字符串

Parameters

mixed $second second
bool $more 是否返回分/秒

Return Value

string

at line 129
static bool|int|string gmStr2Time(string $str)

转换字符串形式的时间表达式为GMT时间戳

Parameters

string $str str

Return Value

bool|int|string

at line 144
static float|string serverTimezone()

获得服务器的时区

Return Value

float|string

at line 158
static string dayStart(string $date = '')

一天的开始, 未传值代表今天

Parameters

string $date date

Return Value

string

at line 171
static string dayEnd(string $date = '')

一天的结束, 未传值代表今天

Parameters

string $date date

Return Value

string

at line 185
static string format(int|string $time = 0, string $format = 'Y-m-d H:i')

格式化日期

Parameters

int|string $time time
string $format format

Return Value

string

at line 201
static bool isEmpty(string $date)

空日期检测

Parameters

string $date date

Return Value

bool

at line 211
static int datetimeToTimestamp(string $datetime)

datetime to timestamp

Parameters

string $datetime datetime

Return Value

int

at line 221
static string timestampToDatetime(string $timestamp)

时间戳转换成 datetime 类型

Parameters

string $timestamp timestamp

Return Value

string

at line 234
static int|string todayStart(bool|false $unix = false) deprecated

deprecated 4.2

获取今日起始时间

Parameters

bool|false $unix unix

Return Value

int|string

See also

dayStart()

at line 252
static int|string todayEnd(bool|false $unix = false) deprecated

deprecated 4.2

获取今日起始时间

Parameters

bool|false $unix unix

Return Value

int|string

See also

dayEnd()

at line 270
static false|string tranTime(mixed $time)

精确时间间隔函数 $time 发布时间 如 1356973323 $str 输出格式 如 Y-m-d H:i:s 半年的秒数为15552000,1年为31104000,此处用半年的时间

Parameters

mixed $time time

Return Value

false|string

at line 311
static string timeSince(string|int $datetime)

Returns a human readable time difference from the value to the current time. Eg: 10 minutes ago

Parameters

string|int $datetime datetime

Return Value

string

at line 324
static string timeTense(mixed $datetime)

Returns 24-hour time and the day using the grammatical tense of the current time. Eg: Today at 12:49, Yesterday at 4:00 or 18 Sep 2015 at 14:33.

Parameters

mixed $datetime datetime

Return Value

string

at line 349
static Carbon|null makeCarbon(Carbon|DateTime|string|int $value)

Converts mixed inputs to a Carbon object.

Parameters

Carbon|DateTime|string|int $value value

Return Value

Carbon|null

at line 378
static string momentFormat(string $format)

Converts a PHP date format to "Moment.js" format.

Parameters

string $format format

Return Value

string

at line 431
static string micro()

返回微秒数值

Return Value

string

at line 444
static string fetchFormat(Carbon|null|string $carbon, string $format = 'Y-m-d H:i:s')

通过 Carbon 对象来获取格式化的时间

Parameters

Carbon|null|string $carbon carbon
string $format format

Return Value

string

at line 464
static array week(string $date, int $start = Carbon::MONDAY)

根据日期返回每年的周数 例如 2020-01-01 会返回 [2019,52] 周, 用于统计部分

Parameters

string $date 日期
int $start 默认以那一天作为第一天的开始

Return Value

array