Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
f8e261e5
Commit
f8e261e5
authored
Jul 30, 2024
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
身份证识别
parent
1784577d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
11 deletions
+38
-11
CheckerHelper.java
.../main/java/com/yanzuoguang/util/helper/CheckerHelper.java
+14
-8
DateHelper.java
...src/main/java/com/yanzuoguang/util/helper/DateHelper.java
+3
-3
TestString.java
yzg-util-base/src/test/java/helper/TestString.java
+21
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/CheckerHelper.java
View file @
f8e261e5
...
...
@@ -230,9 +230,9 @@ public final class CheckerHelper {
/**
* 检测是否符合时间类型
*
* @param paramName
* @param paramVal
* @param queryType
* @param paramName
参数名称
* @param paramVal
值
* @param queryType
格式类型
* @return
*/
public
CheckerHelper
notDateCheck
(
String
paramName
,
String
paramVal
,
String
queryType
)
{
...
...
@@ -364,7 +364,7 @@ public final class CheckerHelper {
*
* @param paramName 参数名称
* @param paramVal 参数值
* @return
* @return
当前对象
*/
public
CheckerHelper
checkDate
(
String
paramName
,
String
paramVal
)
{
return
checkDate
(
paramName
,
paramVal
,
StringHelper
.
EMPTY
);
...
...
@@ -376,7 +376,7 @@ public final class CheckerHelper {
* @param paramName 参数名称
* @param paramVal 参数值
* @param formatStr 日期格式
* @return
* @return
当前对象
*/
public
CheckerHelper
checkDate
(
String
paramName
,
String
paramVal
,
String
formatStr
)
{
if
(!
isValid
())
{
...
...
@@ -386,10 +386,17 @@ public final class CheckerHelper {
return
this
;
}
try
{
getDate
(
paramVal
,
formatStr
);
Date
date
=
getDate
(
paramVal
,
formatStr
);
String
dateResult
=
DateHelper
.
getDateTimeString
(
formatStr
,
date
);
if
(!
dateResult
.
startsWith
(
paramVal
)){
String
formatTo
=
StringHelper
.
getFirst
(
formatStr
,
DateHelper
.
FORMAT_SECOND_STRING
);
this
.
checkResult
=
language
.
format
(
PARAM_NOT_DATE
,
paramName
,
formatTo
);
this
.
setValid
(
false
);
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
this
.
checkResult
=
language
.
format
(
PARAM_NOT_DATE
,
paramName
,
formatStr
);
String
formatTo
=
StringHelper
.
getFirst
(
formatStr
,
DateHelper
.
FORMAT_SECOND_STRING
);
this
.
checkResult
=
language
.
format
(
PARAM_NOT_DATE
,
paramName
,
formatTo
);
this
.
setValid
(
false
);
}
return
this
;
...
...
@@ -400,7 +407,6 @@ public final class CheckerHelper {
SimpleDateFormat
format
=
new
SimpleDateFormat
(
formatStr
);
return
format
.
parse
(
paramVal
);
}
else
{
formatStr
=
DateHelper
.
FORMAT_SECOND_STRING
;
return
DateAutoHelper
.
getAutoDate
(
paramVal
);
}
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateHelper.java
View file @
f8e261e5
...
...
@@ -853,11 +853,11 @@ public class DateHelper {
* @return 转换后的结果
*/
public
static
String
getDateTimeString
(
String
format
,
Date
date
)
{
String
to
=
""
;
if
(
date
!=
null
)
{
to
=
new
SimpleDateFormat
(
format
).
format
(
date
);
String
formatTo
=
StringHelper
.
getFirst
(
format
,
FORMAT_SECOND_STRING
);
return
new
SimpleDateFormat
(
formatTo
).
format
(
date
);
}
return
to
;
return
StringHelper
.
EMPTY
;
}
/**
...
...
yzg-util-base/src/test/java/helper/TestString.java
View file @
f8e261e5
package
helper
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.junit.Test
;
import
java.util.Date
;
public
class
TestString
{
@Test
...
...
@@ -15,4 +19,21 @@ public class TestString {
System
.
out
.
printf
(
"长度:%d 条数:%d%n"
,
content
.
length
(),
page
);
System
.
out
.
printf
(
"长度:%d 条数:%d%n"
,
content1
.
length
(),
page1
);
}
@Test
public
void
testDt
(){
String
dt
=
"2024-24-15 10:24"
;
Date
date
=
DateHelper
.
getDateTime
(
dt
);
String
dtTo
=
DateHelper
.
getDateTimeString
(
date
);
if
(
dtTo
.
startsWith
(
dt
)){
System
.
out
.
println
(
"测试通过"
);
}
else
{
System
.
out
.
println
(
"测试失败"
);
}
}
@Test
public
void
testDtCheckHelper
(){
String
dt
=
"2024-24-15 10:24"
;
CheckerHelper
.
newInstance
().
checkDate
(
"dt"
,
dt
).
checkException
();
}
}
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