Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
曲欣亮
common
Commits
86669446
Commit
86669446
authored
Aug 30, 2021
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
4f36c623
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
DateUtil.java
src/main/java/com/egolm/common/DateUtil.java
+45
-0
No files found.
src/main/java/com/egolm/common/DateUtil.java
View file @
86669446
...
...
@@ -590,5 +590,50 @@ public class DateUtil {
}
return
newTime
;
}
/**
* 获取当前月第一天
* @param month
* @return
*/
public
static
String
getFirstDayOfMonth
(
int
month
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
// 设置月份
calendar
.
set
(
Calendar
.
MONTH
,
month
-
1
);
// 获取某月最小天数
int
firstDay
=
calendar
.
getActualMinimum
(
Calendar
.
DAY_OF_MONTH
);
// 设置日历中月份的最小天数
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
firstDay
);
// 格式化日期
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
sdf
.
format
(
calendar
.
getTime
())+
" 00:00:00"
;
}
/**
* 获取当前月最后一天:
* @param month
* @return
*/
public
static
String
getLastDayOfMonth
(
int
month
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
// 设置月份
calendar
.
set
(
Calendar
.
MONTH
,
month
-
1
);
// 获取某月最大天数
int
lastDay
=
0
;
//2月的平年瑞年天数
if
(
month
==
2
)
{
// 这个api在计算2020年2月的过程中有问题
lastDay
=
calendar
.
getLeastMaximum
(
Calendar
.
DAY_OF_MONTH
);
}
else
{
lastDay
=
calendar
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
);
}
// 设置日历中月份的最大天数
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
lastDay
);
// 格式化日期
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
sdf
.
format
(
calendar
.
getTime
())+
" 23:59:59"
;
}
}
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