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
38334d5a
Commit
38334d5a
authored
Jul 25, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://key@gitlab.egolm.com/key/common.git
parents
bcfe718f
aa71e6cf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
582 additions
and
526 deletions
+582
-526
DateUtil.java
src/main/java/com/egolm/common/DateUtil.java
+200
-147
HttpUtil.java
src/main/java/com/egolm/common/HttpUtil.java
+382
-379
No files found.
src/main/java/com/egolm/common/DateUtil.java
View file @
38334d5a
...
@@ -31,43 +31,55 @@ public class DateUtil {
...
@@ -31,43 +31,55 @@ public class DateUtil {
public
static
final
String
FMT_DATE_ISO
=
"yyyy-MM-ddTHH:mm:ss.SSSZ"
;
public
static
final
String
FMT_DATE_ISO
=
"yyyy-MM-ddTHH:mm:ss.SSSZ"
;
public
static
final
String
FMT_UTC_GMT
=
"EEE, dd MMM yyyy HH:mm:ss z"
;
public
static
final
String
FMT_UTC_GMT
=
"EEE, dd MMM yyyy HH:mm:ss z"
;
public
static
final
String
FMT_YYYYMMddHHMMSS
=
"yyyyMMddHHmmss"
;
public
static
final
String
FMT_YYYYMMddHHMMSS
=
"yyyyMMddHHmmss"
;
public
static
final
String
FMT_UTC_ALIYUN
=
"YYYY-MM-DD'T'hh:mm:ss'Z'"
;
public
static
final
String
FMT_UTC_ALIYUN
=
"YYYY-MM-DD'T'hh:mm:ss'Z'"
;
public
static
final
String
FMT_YYYY_MM
=
"yyyy-MM"
;
public
static
final
String
FMT_YYYY_MM
=
"yyyy-MM"
;
public
static
final
Long
SECOND
=
1000L
;
public
static
final
Long
SECOND
=
1000L
;
public
static
final
Long
MINUTE
=
1000L
*
60
;
public
static
final
Long
MINUTE
=
1000L
*
60
;
public
static
final
Long
HALF_HOUR
=
MINUTE
*
30
;
public
static
final
Long
HALF_HOUR
=
MINUTE
*
30
;
public
static
final
Long
HOUR
=
HALF_HOUR
*
2
;
public
static
final
Long
HOUR
=
HALF_HOUR
*
2
;
public
static
final
Long
HALF_DAY
=
HOUR
*
12
;
public
static
final
Long
HALF_DAY
=
HOUR
*
12
;
public
static
final
Long
DAY
=
HALF_DAY
*
2
;
public
static
final
Long
DAY
=
HALF_DAY
*
2
;
private
static
final
Map
<
Pattern
,
String
>
PATTERN_DATE
=
new
LinkedHashMap
<
Pattern
,
String
>();
private
static
final
Map
<
Pattern
,
String
>
PATTERN_DATE
=
new
LinkedHashMap
<
Pattern
,
String
>();
static
{
static
{
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月(([0]?[1-9])|([1-2][0-9])|([3][0-1]))日\\s+\\d{1,2}时\\d{1,2}分\\d{1,2}秒)"
),
"yyyy年MM月dd日 HH时mm分ss秒"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月(([0]?[1-9])|([1-2][0-9])|([3][0-1]))日\\s+\\d{1,2}:\\d{1,2}:\\d{1,2})"
),
"yyyy年MM月dd日 HH:mm:ss"
);
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月(([0]?[1-9])|([1-2][0-9])|([3][0-1]))日\\s+\\d{1,2}时\\d{1,2}分\\d{1,2}秒)"
),
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月(([0]?[1-9])|([1-2][0-9])|([3][0-1]))日)"
),
"yyyy年MM月dd日"
);
"yyyy年MM月dd日 HH时mm分ss秒"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月(([0]?[1-9])|([1-2][0-9])|([3][0-1]))日\\s+\\d{1,2}:\\d{1,2}:\\d{1,2})"
),
"yyyy年MM月dd日 HH:mm:ss"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月(([0]?[1-9])|([1-2][0-9])|([3][0-1]))日)"
),
"yyyy年MM月dd日"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月)"
),
"yyyy年MM月"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年(([0]?[1-9])|([1][0-2]))月)"
),
"yyyy年MM月"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年)"
),
"yyyy年"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})年)"
),
"yyyy年"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}Z)"
),
DateUtil
.
FMT_DATE_ISO
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}Z)"
),
DateUtil
.
FMT_DATE_ISO
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}/\\d{1,2}/\\d{1,2}\\s+\\d{1,2}:\\d{1,2}:\\d{1,2})"
),
DateUtil
.
FMT_A_DATE_SECOND
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}/\\d{1,2}/\\d{1,2}\\s+\\d{1,2}:\\d{1,2}:\\d{1,2})"
),
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}/\\d{1,2}/\\d{1,2}\\s+\\d{1,2}:\\d{1,2})"
),
DateUtil
.
FMT_A_DATE_MINUTE
);
DateUtil
.
FMT_A_DATE_SECOND
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}/\\d{1,2}/\\d{1,2}\\s+\\d{1,2}:\\d{1,2})"
),
DateUtil
.
FMT_A_DATE_MINUTE
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}/\\d{1,2}/\\d{1,2})"
),
DateUtil
.
FMT_A_DATE
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}/\\d{1,2}/\\d{1,2})"
),
DateUtil
.
FMT_A_DATE
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{1,2}-\\d{1,2}\\s+\\d{1,2}:\\d{1,2}:\\d{1,2})"
),
DateUtil
.
FMT_DATE_SECOND
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{1,2}-\\d{1,2}\\s+\\d{1,2}:\\d{1,2}:\\d{1,2})"
),
DateUtil
.
FMT_DATE_SECOND
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{1,2}-\\d{1,2}\\s+\\d{1,2}:\\d{1,2})"
),
DateUtil
.
FMT_DATE_MINUTE
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{1,2}-\\d{1,2}\\s+\\d{1,2}:\\d{1,2})"
),
DateUtil
.
FMT_DATE_MINUTE
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{1,2}-\\d{1,2})"
),
DateUtil
.
FMT_DATE
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(\\d{4}-\\d{1,2}-\\d{1,2})"
),
DateUtil
.
FMT_DATE
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1])))"
),
"yyyyMMdd"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1])))"
),
"yyyyMMdd"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})(([0][1-9])|([1][0-2])))"
),
"yyyyMM"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"(([1-2][0-9]{3})(([0][1-9])|([1][0-2])))"
),
"yyyyMM"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"([1-2][0-9]{3})"
),
"yyyy"
);
PATTERN_DATE
.
put
(
Pattern
.
compile
(
"([1-2][0-9]{3})"
),
"yyyy"
);
}
}
/**
/**
* 将日期字符串转化成日期类型
* 将日期字符串转化成日期类型
*
* @param date
* @param date
* @param fmt
* @param fmt
* @return
* @return
...
@@ -85,20 +97,21 @@ public class DateUtil {
...
@@ -85,20 +97,21 @@ public class DateUtil {
/**
/**
* 自动判断日期字符串格式并将其转化为日期类型
* 自动判断日期字符串格式并将其转化为日期类型
*
* @param str
* @param str
* @return
* @return
*/
*/
public
static
Date
parse
(
Object
obj
)
{
public
static
Date
parse
(
Object
obj
)
{
if
(
obj
instanceof
Date
)
{
if
(
obj
instanceof
Date
)
{
return
new
Date
(((
Date
)
obj
).
getTime
());
return
new
Date
(((
Date
)
obj
).
getTime
());
}
else
{
}
else
{
String
str
=
String
.
valueOf
(
obj
).
trim
();
String
str
=
String
.
valueOf
(
obj
).
trim
();
if
(
StringUtil
.
isNotEmpty
(
str
))
{
if
(
StringUtil
.
isNotEmpty
(
str
))
{
for
(
Pattern
pattern
:
PATTERN_DATE
.
keySet
())
{
for
(
Pattern
pattern
:
PATTERN_DATE
.
keySet
())
{
Matcher
matcher
=
pattern
.
matcher
(
str
);
Matcher
matcher
=
pattern
.
matcher
(
str
);
if
(
matcher
.
find
())
{
if
(
matcher
.
find
())
{
String
date_str
=
matcher
.
group
(
1
);
String
date_str
=
matcher
.
group
(
1
);
if
(
PATTERN_DATE
.
get
(
pattern
).
equals
(
DateUtil
.
FMT_DATE_ISO
))
{
if
(
PATTERN_DATE
.
get
(
pattern
).
equals
(
DateUtil
.
FMT_DATE_ISO
))
{
return
parseISODate
(
date_str
);
return
parseISODate
(
date_str
);
}
else
{
}
else
{
return
parse
(
date_str
,
PATTERN_DATE
.
get
(
pattern
));
return
parse
(
date_str
,
PATTERN_DATE
.
get
(
pattern
));
...
@@ -122,14 +135,14 @@ public class DateUtil {
...
@@ -122,14 +135,14 @@ public class DateUtil {
}
}
public
static
boolean
isDate
(
Object
obj
)
{
public
static
boolean
isDate
(
Object
obj
)
{
if
(
obj
instanceof
Date
)
{
if
(
obj
instanceof
Date
)
{
return
true
;
return
true
;
}
else
{
}
else
{
String
str
=
String
.
valueOf
(
obj
);
String
str
=
String
.
valueOf
(
obj
);
if
(
StringUtil
.
isNotEmpty
(
str
))
{
if
(
StringUtil
.
isNotEmpty
(
str
))
{
String
date_str
=
str
.
trim
();
String
date_str
=
str
.
trim
();
for
(
Pattern
pattern
:
PATTERN_DATE
.
keySet
())
{
for
(
Pattern
pattern
:
PATTERN_DATE
.
keySet
())
{
if
(
pattern
.
matcher
(
date_str
).
find
())
{
if
(
pattern
.
matcher
(
date_str
).
find
())
{
return
true
;
return
true
;
}
}
}
}
...
@@ -140,12 +153,13 @@ public class DateUtil {
...
@@ -140,12 +153,13 @@ public class DateUtil {
/**
/**
* 格式化日期为字符串
* 格式化日期为字符串
*
* @param date
* @param date
* @param fmt
* @param fmt
* @return
* @return
*/
*/
public
static
String
format
(
Date
date
,
String
fmt
)
{
public
static
String
format
(
Date
date
,
String
fmt
)
{
if
(
date
==
null
)
{
if
(
date
==
null
)
{
return
null
;
return
null
;
}
else
{
}
else
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
fmt
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
fmt
);
...
@@ -155,6 +169,7 @@ public class DateUtil {
...
@@ -155,6 +169,7 @@ public class DateUtil {
/**
/**
* 格式化为yyyy-MM-dd格式
* 格式化为yyyy-MM-dd格式
*
* @param date 时间参数
* @param date 时间参数
* @return yyyy-MM-dd
* @return yyyy-MM-dd
*/
*/
...
@@ -164,6 +179,7 @@ public class DateUtil {
...
@@ -164,6 +179,7 @@ public class DateUtil {
/**
/**
* 格式化日期为yyyy-MM-dd HH:mm:ss格式
* 格式化日期为yyyy-MM-dd HH:mm:ss格式
*
* @param date
* @param date
* @return yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
*/
*/
...
@@ -185,13 +201,13 @@ public class DateUtil {
...
@@ -185,13 +201,13 @@ public class DateUtil {
}
}
/**
/**
* 将毫秒数格式化成默认格式日期字符串
* 将毫秒数格式化成默认格式日期字符串
默认格式:yyyy-MM-dd HH:mm:ss
*
默认格式:yyyy-MM-dd HH:mm:ss
*
* @param time
* @param time
* @return
* @return
*/
*/
public
static
String
format
(
Long
time
)
{
public
static
String
format
(
Long
time
)
{
if
(
time
!=
null
)
{
if
(
time
!=
null
)
{
Date
date
=
new
Date
(
time
);
Date
date
=
new
Date
(
time
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
DateUtil
.
FMT_DATE_SECOND
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
DateUtil
.
FMT_DATE_SECOND
);
return
sdf
.
format
(
date
);
return
sdf
.
format
(
date
);
...
@@ -202,12 +218,13 @@ public class DateUtil {
...
@@ -202,12 +218,13 @@ public class DateUtil {
/**
/**
* 将毫秒数格式化为制定格式的日期字符串
* 将毫秒数格式化为制定格式的日期字符串
*
* @param time
* @param time
* @param fmt
* @param fmt
* @return
* @return
*/
*/
public
static
String
format
(
Long
time
,
String
fmt
)
{
public
static
String
format
(
Long
time
,
String
fmt
)
{
if
(
time
!=
null
)
{
if
(
time
!=
null
)
{
Date
date
=
new
Date
(
time
);
Date
date
=
new
Date
(
time
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
fmt
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
fmt
);
return
sdf
.
format
(
date
);
return
sdf
.
format
(
date
);
...
@@ -217,8 +234,8 @@ public class DateUtil {
...
@@ -217,8 +234,8 @@ public class DateUtil {
}
}
/**
/**
* 将毫秒数格式化为时间格式字符串
* 将毫秒数格式化为时间格式字符串
毫秒数必须小于86400000
*
毫秒数必须小于86400000
*
* @param time
* @param time
* @return
* @return
*/
*/
...
@@ -227,16 +244,16 @@ public class DateUtil {
...
@@ -227,16 +244,16 @@ public class DateUtil {
}
}
/**
/**
* 将毫秒数格式化为时间格式字符串
* 将毫秒数格式化为时间格式字符串
毫秒数必须小于86400000
*
毫秒数必须小于86400000
*
* @param time
* @param time
* @param fmt
* @param fmt
* @return
* @return
*/
*/
public
static
String
format
(
Integer
time
,
String
fmt
)
{
public
static
String
format
(
Integer
time
,
String
fmt
)
{
if
(
time
!=
null
)
{
if
(
time
!=
null
)
{
if
(
time
<
86400000
)
{
if
(
time
<
86400000
)
{
Date
date
=
new
Date
(
time
-
(
1000
*
60
*
60
*
8
));
Date
date
=
new
Date
(
time
-
(
1000
*
60
*
60
*
8
));
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
fmt
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
fmt
);
return
sdf
.
format
(
date
);
return
sdf
.
format
(
date
);
}
else
{
}
else
{
...
@@ -249,6 +266,7 @@ public class DateUtil {
...
@@ -249,6 +266,7 @@ public class DateUtil {
/**
/**
* 计算指定时间当天的开始时间
* 计算指定时间当天的开始时间
*
* @param time
* @param time
* @return
* @return
* @throws ParseException
* @throws ParseException
...
@@ -260,12 +278,13 @@ public class DateUtil {
...
@@ -260,12 +278,13 @@ public class DateUtil {
/**
/**
* 计算指定时间当天的开始时间
* 计算指定时间当天的开始时间
*
* @param time
* @param time
* @return
* @return
* @throws ParseException
* @throws ParseException
*/
*/
public
static
Date
start
(
Date
time
)
{
public
static
Date
start
(
Date
time
)
{
if
(
time
!=
null
)
{
if
(
time
!=
null
)
{
return
parse
(
format
(
time
,
DateUtil
.
FMT_DATE
),
DateUtil
.
FMT_DATE
);
return
parse
(
format
(
time
,
DateUtil
.
FMT_DATE
),
DateUtil
.
FMT_DATE
);
}
else
{
}
else
{
return
null
;
return
null
;
...
@@ -274,13 +293,14 @@ public class DateUtil {
...
@@ -274,13 +293,14 @@ public class DateUtil {
/**
/**
* 计算指定日期当天的最后时间
* 计算指定日期当天的最后时间
*
* @param time
* @param time
* @return
* @return
* @throws ParseException
* @throws ParseException
*/
*/
public
static
Date
end
(
Date
time
)
{
public
static
Date
end
(
Date
time
)
{
if
(
time
!=
null
)
{
if
(
time
!=
null
)
{
return
new
Date
(
start
(
new
Date
(
time
.
getTime
()
+
(
24L
*
60L
*
60L
*
1000L
))).
getTime
());
return
new
Date
(
start
(
new
Date
(
time
.
getTime
()
+
(
24L
*
60L
*
60L
*
1000L
))).
getTime
());
}
else
{
}
else
{
return
null
;
return
null
;
}
}
...
@@ -288,17 +308,19 @@ public class DateUtil {
...
@@ -288,17 +308,19 @@ public class DateUtil {
/**
/**
* 取得当前时间向后或向前若干天的时间
* 取得当前时间向后或向前若干天的时间
*
* @param time
* @param time
* @param offset
* @param offset
* @return
* @return
*/
*/
public
static
Date
day
(
Date
time
,
Integer
offset
)
{
public
static
Date
day
(
Date
time
,
Integer
offset
)
{
Date
date
=
new
Date
(
time
.
getTime
()
+
(
offset
*
86400000L
));
Date
date
=
new
Date
(
time
.
getTime
()
+
(
offset
*
86400000L
));
return
date
;
return
date
;
}
}
/**
/**
* 计算指定的日期是星期几,返回数字 周日至周六分别是0-6
* 计算指定的日期是星期几,返回数字 周日至周六分别是0-6
*
* @param date
* @param date
* @return
* @return
*/
*/
...
@@ -310,6 +332,7 @@ public class DateUtil {
...
@@ -310,6 +332,7 @@ public class DateUtil {
/**
/**
* 计算两天之间相隔多少天
* 计算两天之间相隔多少天
*
* @param start
* @param start
* @param end
* @param end
* @return
* @return
...
@@ -317,11 +340,12 @@ public class DateUtil {
...
@@ -317,11 +340,12 @@ public class DateUtil {
public
static
Integer
days
(
Date
start
,
Date
end
)
{
public
static
Integer
days
(
Date
start
,
Date
end
)
{
Date
date_start
=
start
(
start
);
Date
date_start
=
start
(
start
);
Date
date_end
=
start
(
end
);
Date
date_end
=
start
(
end
);
return
(
int
)((
date_end
.
getTime
()
-
date_start
.
getTime
())
/
86400000L
);
return
(
int
)
((
date_end
.
getTime
()
-
date_start
.
getTime
())
/
86400000L
);
}
}
/**
/**
* 判断是否是今天
* 判断是否是今天
*
* @param date
* @param date
* @return
* @return
*/
*/
...
@@ -329,7 +353,7 @@ public class DateUtil {
...
@@ -329,7 +353,7 @@ public class DateUtil {
Date
today
=
new
Date
();
Date
today
=
new
Date
();
Date
start
=
start
(
today
);
Date
start
=
start
(
today
);
Date
end
=
end
(
today
);
Date
end
=
end
(
today
);
if
(
date
.
getTime
()
>=
start
.
getTime
()
&&
date
.
getTime
()
<
end
.
getTime
())
{
if
(
date
.
getTime
()
>=
start
.
getTime
()
&&
date
.
getTime
()
<
end
.
getTime
())
{
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
...
@@ -338,6 +362,7 @@ public class DateUtil {
...
@@ -338,6 +362,7 @@ public class DateUtil {
/**
/**
* 取得当前日期是多少周
* 取得当前日期是多少周
*
* @param date
* @param date
* @return
* @return
*/
*/
...
@@ -345,12 +370,13 @@ public class DateUtil {
...
@@ -345,12 +370,13 @@ public class DateUtil {
Calendar
c
=
new
GregorianCalendar
();
Calendar
c
=
new
GregorianCalendar
();
c
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
c
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
c
.
setMinimalDaysInFirstWeek
(
7
);
c
.
setMinimalDaysInFirstWeek
(
7
);
c
.
setTime
(
date
);
c
.
setTime
(
date
);
return
c
.
get
(
Calendar
.
WEEK_OF_YEAR
);
return
c
.
get
(
Calendar
.
WEEK_OF_YEAR
);
}
}
/**
/**
* 得到某一年周的总数
* 得到某一年周的总数
*
* @param year
* @param year
* @return
* @return
*/
*/
...
@@ -362,6 +388,7 @@ public class DateUtil {
...
@@ -362,6 +388,7 @@ public class DateUtil {
/**
/**
* 得到某年某周的第一天
* 得到某年某周的第一天
*
* @param year
* @param year
* @param week
* @param week
* @return
* @return
...
@@ -369,15 +396,16 @@ public class DateUtil {
...
@@ -369,15 +396,16 @@ public class DateUtil {
public
static
Date
getFirstDayOfWeek
(
int
year
,
int
week
)
{
public
static
Date
getFirstDayOfWeek
(
int
year
,
int
week
)
{
Calendar
c
=
new
GregorianCalendar
();
Calendar
c
=
new
GregorianCalendar
();
c
.
set
(
Calendar
.
YEAR
,
year
);
c
.
set
(
Calendar
.
YEAR
,
year
);
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
JANUARY
);
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
JANUARY
);
c
.
set
(
Calendar
.
DATE
,
1
);
c
.
set
(
Calendar
.
DATE
,
1
);
Calendar
cal
=
(
GregorianCalendar
)
c
.
clone
();
Calendar
cal
=
(
GregorianCalendar
)
c
.
clone
();
cal
.
add
(
Calendar
.
DATE
,
week
*
7
);
cal
.
add
(
Calendar
.
DATE
,
week
*
7
);
return
getFirstDayOfWeek
(
cal
.
getTime
());
return
getFirstDayOfWeek
(
cal
.
getTime
());
}
}
/**
/**
* 得到某年某周的最后一天
* 得到某年某周的最后一天
*
* @param year
* @param year
* @param week
* @param week
* @return
* @return
...
@@ -388,12 +416,13 @@ public class DateUtil {
...
@@ -388,12 +416,13 @@ public class DateUtil {
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
JANUARY
);
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
JANUARY
);
c
.
set
(
Calendar
.
DATE
,
1
);
c
.
set
(
Calendar
.
DATE
,
1
);
Calendar
cal
=
(
GregorianCalendar
)
c
.
clone
();
Calendar
cal
=
(
GregorianCalendar
)
c
.
clone
();
cal
.
add
(
Calendar
.
DATE
,
week
*
7
);
cal
.
add
(
Calendar
.
DATE
,
week
*
7
);
return
getLastDayOfWeek
(
cal
.
getTime
());
return
getLastDayOfWeek
(
cal
.
getTime
());
}
}
/**
/**
* 取得当前日期所在周的第一天
* 取得当前日期所在周的第一天
*
* @param date
* @param date
* @return
* @return
*/
*/
...
@@ -402,11 +431,12 @@ public class DateUtil {
...
@@ -402,11 +431,12 @@ public class DateUtil {
c
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
c
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
c
.
setTime
(
date
);
c
.
setTime
(
date
);
c
.
set
(
Calendar
.
DAY_OF_WEEK
,
c
.
getFirstDayOfWeek
());
// Monday
c
.
set
(
Calendar
.
DAY_OF_WEEK
,
c
.
getFirstDayOfWeek
());
// Monday
return
c
.
getTime
();
return
c
.
getTime
();
}
}
/**
/**
* 取得当前日期所在周的最后一天
* 取得当前日期所在周的最后一天
*
* @param date
* @param date
* @return
* @return
*/
*/
...
@@ -420,29 +450,32 @@ public class DateUtil {
...
@@ -420,29 +450,32 @@ public class DateUtil {
/**
/**
* 取得当前日期所在月的第一天
* 取得当前日期所在月的第一天
*
* @param date
* @param date
* @return
* @return
*/
*/
public
static
Date
getFirstDayOfMonth
(
Date
date
){
public
static
Date
getFirstDayOfMonth
(
Date
date
)
{
Calendar
c
=
Calendar
.
getInstance
();
Calendar
c
=
Calendar
.
getInstance
();
c
.
add
(
Calendar
.
MONTH
,
0
);
c
.
add
(
Calendar
.
MONTH
,
0
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
//设置为1号,当前日期既为本月第一天
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
// 设置为1号,当前日期既为本月第一天
return
c
.
getTime
();
return
c
.
getTime
();
}
}
/**
* 获取指定日期下个月的第一天 的日期
/**
*
* * 获取指定日期下个月的第一天 的日期
*
* @param dateStr
* @param dateStr
* @param format
* @param format
* @return
* @return
*/
*/
public
static
String
getFirstDayOfNextMonth
(
String
dateStr
,
String
format
){
public
static
String
getFirstDayOfNextMonth
(
String
dateStr
,
String
format
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
format
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
format
);
try
{
try
{
Date
date
=
sdf
.
parse
(
dateStr
);
Date
date
=
sdf
.
parse
(
dateStr
);
Calendar
calendar
=
Calendar
.
getInstance
();
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
add
(
Calendar
.
MONTH
,
1
);
calendar
.
add
(
Calendar
.
MONTH
,
1
);
return
sdf
.
format
(
calendar
.
getTime
());
return
sdf
.
format
(
calendar
.
getTime
());
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
...
@@ -451,13 +484,13 @@ public class DateUtil {
...
@@ -451,13 +484,13 @@ 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
);
//
获取前一个月第一天
//
获取前一个月第一天
Calendar
calendar1
=
Calendar
.
getInstance
();
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
add
(
Calendar
.
MONTH
,
month
);
calendar1
.
add
(
Calendar
.
MONTH
,
month
);
calendar1
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar1
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
return
sdf
.
format
(
calendar1
.
getTime
());
return
sdf
.
format
(
calendar1
.
getTime
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -472,7 +505,7 @@ public class DateUtil {
...
@@ -472,7 +505,7 @@ public class DateUtil {
/**
/**
* 获取指定小时前的日期
* 获取指定小时前的日期
*/
*/
public
static
String
beforeHourDay
(
String
fmt
,
int
hour
)
{
public
static
String
beforeHourDay
(
String
fmt
,
int
hour
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)
-
hour
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)
-
hour
);
return
format
(
calendar
.
getTime
(),
fmt
);
return
format
(
calendar
.
getTime
(),
fmt
);
...
@@ -523,4 +556,24 @@ public class DateUtil {
...
@@ -523,4 +556,24 @@ public class DateUtil {
return
list
;
return
list
;
}
}
/**
* 时间加8小时,时区问题
* <p>Title: </p>
* <p>Description: </p>
* @param time
* @return
*/
public
static
String
formatTimeEight
(
String
time
)
{
String
newTime
=
time
;
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
FMT_DATE_SECOND
);
Date
d
=
sdf
.
parse
(
time
);
long
rightTime
=
(
long
)
(
d
.
getTime
()
+
8
*
60
*
60
*
1000
);
newTime
=
sdf
.
format
(
rightTime
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
return
newTime
;
}
}
}
src/main/java/com/egolm/common/HttpUtil.java
View file @
38334d5a
...
@@ -261,11 +261,14 @@ public class HttpUtil {
...
@@ -261,11 +261,14 @@ public class HttpUtil {
:
(
val
instanceof
Object
[]
?
(
Object
[])
val
:
new
Object
[]
{
val
}));
:
(
val
instanceof
Object
[]
?
(
Object
[])
val
:
new
Object
[]
{
val
}));
if
(
sVals
!=
null
&&
sVals
.
length
>
0
)
{
if
(
sVals
!=
null
&&
sVals
.
length
>
0
)
{
for
(
Object
sVal
:
sVals
)
{
for
(
Object
sVal
:
sVals
)
{
params
.
add
(
sKey
+
"="
+
(
sVal
==
null
?
""
:
sVal
));
if
(
StringUtil
.
isNotEmpty
(
sVal
))
{
params
.
add
(
sKey
+
"="
+
sVal
);
}
}
}
}
else
{
params
.
add
(
sKey
+
"="
);
}
}
/*else {
params.add(sKey + "="); 空值不参与签名
}*/
}
}
}
}
return
StringUtil
.
join
(
"&"
,
params
);
return
StringUtil
.
join
(
"&"
,
params
);
...
...
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