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
929e5963
Commit
929e5963
authored
Sep 22, 2023
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加某个月的最后一天
parent
6a5080cc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
4 deletions
+28
-4
DateUtil.java
src/main/java/com/egolm/common/DateUtil.java
+28
-4
No files found.
src/main/java/com/egolm/common/DateUtil.java
View file @
929e5963
...
@@ -275,9 +275,6 @@ public class DateUtil {
...
@@ -275,9 +275,6 @@ public class DateUtil {
}
}
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
format
(
Integer
.
MAX_VALUE
));
}
/**
/**
* 计算指定时间当天的开始时间
* 计算指定时间当天的开始时间
...
@@ -476,6 +473,16 @@ public class DateUtil {
...
@@ -476,6 +473,16 @@ public class DateUtil {
return
c
.
getTime
();
return
c
.
getTime
();
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
getLastMonth
(
FMT_DATE
,-
1
));
System
.
out
.
println
(
getLastMonthAndLastDay
(
FMT_DATE
,-
1
));
}
/**
/**
*
*
* * 获取指定日期下个月的第一天 的日期
* * 获取指定日期下个月的第一天 的日期
...
@@ -499,6 +506,7 @@ public class DateUtil {
...
@@ -499,6 +506,7 @@ public class DateUtil {
return
null
;
return
null
;
}
}
//获取某月的第一天
public
static
String
getLastMonth
(
String
format
,
int
month
)
{
public
static
String
getLastMonth
(
String
format
,
int
month
)
{
try
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
format
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
format
);
...
@@ -513,6 +521,22 @@ public class DateUtil {
...
@@ -513,6 +521,22 @@ public class DateUtil {
return
null
;
return
null
;
}
}
//获取某月的最后一天
public
static
String
getLastMonthAndLastDay
(
String
format
,
int
month
)
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
format
);
// 获取前一个月第一天
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
add
(
Calendar
.
MONTH
,
month
);
calendar1
.
set
(
Calendar
.
DAY_OF_MONTH
,
calendar1
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
return
sdf
.
format
(
calendar1
.
getTime
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
String
getTimeStamp
()
{
public
static
String
getTimeStamp
()
{
return
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
return
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
}
}
...
...
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