Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-micro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-micro
Commits
85d38a53
Commit
85d38a53
authored
Nov 19, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加时间工具类
parent
f68443a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
Timer.php
src/Tools/Timer.php
+60
-0
No files found.
src/Tools/Timer.php
0 → 100644
View file @
85d38a53
<?php
/**
* Created by PhpStorm.
* User: Zero
* Time: 2020/11/19 15:35
*/
namespace
Meibuyu\Micro\Tools
;
class
Timer
{
/**
* 获取时间区间
* @param int $num 正数为向后取时间,负数为向前取时间
* @param string $type 支持 year month day hour minute second
* @param string $begin 开始时间,默认此时此刻
* @param string $format
* @return array
* @author Zero
*/
public
static
function
getRange
(
int
$num
,
string
$type
,
string
$begin
=
null
,
string
$format
=
null
)
{
switch
(
$type
)
{
case
'year'
:
!
$format
&&
$format
=
'Y'
;
break
;
case
'month'
:
!
$format
&&
$format
=
'Y-m'
;
break
;
case
'day'
:
!
$format
&&
$format
=
'Y-m-d'
;
break
;
case
'hour'
:
!
$format
&&
$format
=
'Y-m-d H'
;
break
;
case
'minute'
:
!
$format
&&
$format
=
'Y-m-d H:i'
;
break
;
case
'second'
:
!
$format
&&
$format
=
'Y-m-d H:i:s'
;
break
;
}
$timeStr
=
$type
.
's'
;
$begin
=
$begin
?
strtotime
(
$begin
)
:
time
();
$end
=
strtotime
(
"+
{
$num
}
{
$timeStr
}
"
,
$begin
);
if
(
$begin
>
$end
)
{
// 如果开始时间比结束时间大,则反转
$temp
=
$begin
;
$begin
=
$end
;
$end
=
$temp
;
}
$data
=
[];
while
(
$begin
<=
$end
)
{
$data
[]
=
date
(
$format
,
$begin
);
$begin
=
strtotime
(
"+1
{
$timeStr
}
"
,
$begin
);
}
return
$data
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment