Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sap-service
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
曲欣亮
sap-service
Commits
355f14f2
Commit
355f14f2
authored
Jul 26, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
2be3148e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
37 deletions
+28
-37
DateUtil.java
src/main/java/com/egolm/sso/util/DateUtil.java
+28
-37
No files found.
src/main/java/com/egolm/sso/util/DateUtil.java
View file @
355f14f2
...
@@ -7,6 +7,8 @@ import java.util.Date;
...
@@ -7,6 +7,8 @@ import java.util.Date;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
com.egolm.sso.config.XRException
;
public
class
DateUtil
{
public
class
DateUtil
{
private
static
Map
<
String
,
DateFormat
>
fmtMap
=
new
HashMap
<>();
private
static
Map
<
String
,
DateFormat
>
fmtMap
=
new
HashMap
<>();
...
@@ -16,44 +18,33 @@ public class DateUtil {
...
@@ -16,44 +18,33 @@ public class DateUtil {
public
static
final
String
FMT_DATE_TIME
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
FMT_DATE_TIME
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
FMT_DATETIME
=
"yyyyMMddHHmmss"
;
public
static
final
String
FMT_DATETIME
=
"yyyyMMddHHmmss"
;
public
static
String
formatDate
(
Date
date
,
String
fmt
)
{
public
static
String
formatDate
(
Date
d
,
String
fmt
)
{
DateFormat
df
=
getFmt
(
fmt
);
DateFormat
df
=
getFmt
(
fmt
);
return
formatDate
(
d
,
df
);
return
formatDate
(
d
ate
,
df
);
}
}
public
static
String
formatDate
(
Date
d
,
DateFormat
fmt
)
{
public
static
String
formatDate
(
Date
date
,
DateFormat
fmt
)
{
return
fmt
.
format
(
d
);
return
fmt
.
format
(
date
);
}
public
static
Date
parseDate
(
String
d
,
String
fmt
)
{
DateFormat
df
=
getFmt
(
fmt
);
return
parseDate
(
d
,
df
);
}
}
public
static
Date
parseDate
(
String
d
,
DateFormat
fmt
)
{
public
static
Object
parseDate
(
String
dateString
,
String
fmt
)
{
if
(
"00000000"
.
equals
(
dateString
))
{
return
"0000-00-00"
;
}
else
{
try
{
try
{
return
fmt
.
parse
(
d
);
DateFormat
df
=
getFmt
(
fmt
);
return
df
.
parse
(
dateString
);
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
throw
new
RuntimeException
(
d
+
" parse to"
+
fmt
,
e
);
throw
new
XRException
(
e
);
}
}
}
}
public
static
Date
parseDateNoEmpty
(
String
d
,
String
fmt
)
{
Date
res
;
if
(
d
!=
null
&&!
d
.
equals
(
""
))
{
res
=
parseDate
(
d
,
fmt
);
}
else
{
res
=
new
Date
(
0
);
}
return
res
;
}
}
public
static
Date
parseDateNoEmpty
(
String
d
,
DateFormat
fmt
)
{
public
static
Object
parseDateNoEmpty
(
String
dateString
,
String
fmt
)
{
Date
res
;
Object
res
;
if
(
d
!=
null
&&!
d
.
equals
(
""
))
{
if
(
dateString
!=
null
&&
!
dateString
.
equals
(
""
))
{
res
=
parseDate
(
d
,
fmt
);
res
=
parseDate
(
d
ateString
,
fmt
);
}
else
{
}
else
{
res
=
new
Date
(
0
);
res
=
new
Date
(
0
);
}
}
return
res
;
return
res
;
...
@@ -61,7 +52,7 @@ public class DateUtil {
...
@@ -61,7 +52,7 @@ public class DateUtil {
public
static
DateFormat
getFmt
(
String
fmt
)
{
public
static
DateFormat
getFmt
(
String
fmt
)
{
DateFormat
df
=
fmtMap
.
get
(
fmt
);
DateFormat
df
=
fmtMap
.
get
(
fmt
);
if
(
df
==
null
)
{
if
(
df
==
null
)
{
df
=
new
SimpleDateFormat
(
fmt
);
df
=
new
SimpleDateFormat
(
fmt
);
fmtMap
.
put
(
fmt
,
df
);
fmtMap
.
put
(
fmt
,
df
);
}
}
...
...
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