Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftMtMx
Overview
Overview
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
isc-v3.1-tmp
swiftMtMx
Commits
d7139ffc
Commit
d7139ffc
authored
Dec 18, 2023
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交业务要素转ISO的测试程序
parent
f6ca4161
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
SwiftIsoUtil.java
swiftCore/src/test/java/com/brilliance/SwiftIsoUtil.java
+85
-0
No files found.
swiftCore/src/test/java/com/brilliance/SwiftIsoUtil.java
0 → 100644
View file @
d7139ffc
package
com
.
brilliance
;
import
com.brilliance.swift.exception.SwiftException
;
import
com.brilliance.swift.util.StringUtil
;
import
javax.xml.datatype.DatatypeConfigurationException
;
import
javax.xml.datatype.DatatypeFactory
;
import
javax.xml.datatype.XMLGregorianCalendar
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.TimeZone
;
public
class
SwiftIsoUtil
{
public
static
String
mt_to_mxDateTime
(
String
mtDateTime
,
int
zoneOffset
)
{
if
(
StringUtil
.
isEmpty
(
mtDateTime
))
{
throw
new
SwiftException
(
"MT日期时间转MX日期时间失败:MT日期时间为空"
);
}
SimpleDateFormat
mtFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmmZ"
);
mtFormat
.
setLenient
(
false
);
Date
mtDate
;
try
{
mtDate
=
mtFormat
.
parse
(
mtDateTime
);
}
catch
(
ParseException
e
)
{
try
{
mtDate
=
mtFormat
.
parse
(
"20"
+
mtDateTime
);
}
catch
(
ParseException
ex
)
{
throw
new
SwiftException
(
"MT日期时间转MX日期时间失败:MT日期时间("
+
mtDateTime
+
")格式不合法"
,
ex
);
}
}
GregorianCalendar
gregorianCalendar
=
new
GregorianCalendar
();
gregorianCalendar
.
setTime
(
mtDate
);
XMLGregorianCalendar
xmlGregorianCalendar
;
try
{
xmlGregorianCalendar
=
DatatypeFactory
.
newInstance
().
newXMLGregorianCalendar
(
gregorianCalendar
);
}
catch
(
DatatypeConfigurationException
e
)
{
throw
new
SwiftException
(
"MT日期时间转MX日期时间失败"
,
e
);
}
xmlGregorianCalendar
.
setTimezone
(
zoneOffset
*
60
);
return
xmlGregorianCalendar
.
toXMLFormat
();
}
public
static
String
dateTransfer
(
String
mtDateTime
)
{
if
(
StringUtil
.
isEmpty
(
mtDateTime
))
{
throw
new
SwiftException
(
"MT日期时间转MX日期时间失败:MT日期时间为空"
);
}
String
[]
split
=
mtDateTime
.
split
(
"[+-]"
,
-
1
);
if
(
split
.
length
==
2
)
{
SimpleDateFormat
mtFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmm"
);
mtFormat
.
setLenient
(
false
);
SimpleDateFormat
mxFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:00"
);
String
mxDateTime
=
null
;
try
{
mxDateTime
=
mxFormat
.
format
(
mtFormat
.
parse
(
split
[
0
]));
}
catch
(
ParseException
e
)
{
try
{
mxDateTime
=
mxFormat
.
format
(
mtFormat
.
parse
(
"20"
+
split
[
0
]));
}
catch
(
ParseException
ignore
)
{
}
}
if
(
mxDateTime
!=
null
&&
split
[
1
].
matches
(
"((0\\d)|(1[0-3]))([0-5]\\d)?"
))
{
mxDateTime
=
mxDateTime
+
mtDateTime
.
charAt
(
mtDateTime
.
length
()
-
split
[
1
].
length
()
-
1
)
+
split
[
1
].
substring
(
0
,
2
)
+
":"
;
mxDateTime
+=
(
split
[
1
].
length
()
>
2
?
split
[
1
].
substring
(
2
)
:
"00"
);
return
mxDateTime
;
}
}
throw
new
SwiftException
(
"MT日期时间转MX日期时间失败:MT日期时间("
+
mtDateTime
+
")格式不合法"
);
}
public
static
String
date2IsoDateTime
(
String
dateStr
)
throws
ParseException
{
SimpleDateFormat
inputFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
Date
date
=
inputFormat
.
parse
(
dateStr
);
SimpleDateFormat
outputFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.sss"
);
outputFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
// 设置为东八区(北京时间)
String
formattedDate
=
outputFormat
.
format
(
date
);
System
.
out
.
println
(
formattedDate
);
return
formattedDate
+
"+00:00"
;
}
}
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