mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-10-16 06:40:23 +00:00
修正issue:IA73GT反馈的时间类型转换问题
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.gitee.dbswitch.common.util;
|
package com.gitee.dbswitch.common.util;
|
||||||
|
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
@@ -487,8 +489,8 @@ public final class ObjectCastUtils {
|
|||||||
}
|
}
|
||||||
} else if (in instanceof String || in instanceof Character) {
|
} else if (in instanceof String || in instanceof Character) {
|
||||||
try {
|
try {
|
||||||
java.sql.Date date = java.sql.Date.valueOf(in.toString());
|
DateTime dt = DateUtil.parse(in.toString());
|
||||||
LocalDate localDate = Instant.ofEpochMilli(date.getTime())
|
LocalDate localDate = Instant.ofEpochMilli(dt.toSqlDate().getTime())
|
||||||
.atZone(ZoneId.systemDefault())
|
.atZone(ZoneId.systemDefault())
|
||||||
.toLocalDate();
|
.toLocalDate();
|
||||||
return localDate;
|
return localDate;
|
||||||
@@ -502,8 +504,8 @@ public final class ObjectCastUtils {
|
|||||||
if (null == v) {
|
if (null == v) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
java.sql.Date date = java.sql.Date.valueOf(v);
|
DateTime dt = DateUtil.parse(in.toString());
|
||||||
LocalDate localDate = Instant.ofEpochMilli(date.getTime())
|
LocalDate localDate = Instant.ofEpochMilli(dt.toSqlDate().getTime())
|
||||||
.atZone(ZoneId.systemDefault())
|
.atZone(ZoneId.systemDefault())
|
||||||
.toLocalDate();
|
.toLocalDate();
|
||||||
return localDate;
|
return localDate;
|
||||||
@@ -576,8 +578,8 @@ public final class ObjectCastUtils {
|
|||||||
}
|
}
|
||||||
} else if (in instanceof String || in instanceof Character) {
|
} else if (in instanceof String || in instanceof Character) {
|
||||||
try {
|
try {
|
||||||
java.sql.Time date = java.sql.Time.valueOf(in.toString());
|
DateTime dt = DateUtil.parse(in.toString());
|
||||||
return LocalTime.ofSecondOfDay(date.getTime());
|
return LocalTime.ofSecondOfDay(dt.toSqlDate().getTime());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
String.format("无法将java.lang.String类型转换为java.sql.Time类型:%s", e.getMessage()));
|
String.format("无法将java.lang.String类型转换为java.sql.Time类型:%s", e.getMessage()));
|
||||||
@@ -588,8 +590,8 @@ public final class ObjectCastUtils {
|
|||||||
if (null == v) {
|
if (null == v) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
java.sql.Time date = java.sql.Time.valueOf(v);
|
DateTime dt = DateUtil.parse(in.toString());
|
||||||
return LocalTime.ofSecondOfDay(date.getTime());
|
return LocalTime.ofSecondOfDay(dt.toSqlDate().getTime());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
String.format("无法将java.sql.Clob类型转换为java.sql.Time类型:%s", e.getMessage()));
|
String.format("无法将java.sql.Clob类型转换为java.sql.Time类型:%s", e.getMessage()));
|
||||||
@@ -671,9 +673,9 @@ public final class ObjectCastUtils {
|
|||||||
}
|
}
|
||||||
} else if (in instanceof String || in instanceof Character) {
|
} else if (in instanceof String || in instanceof Character) {
|
||||||
try {
|
try {
|
||||||
java.sql.Timestamp t = java.sql.Timestamp.valueOf(in.toString());
|
DateTime dt = DateUtil.parse(in.toString());
|
||||||
LocalDateTime localDateTime = LocalDateTime
|
LocalDateTime localDateTime = LocalDateTime
|
||||||
.ofInstant(t.toInstant(), ZoneId.systemDefault());
|
.ofInstant(dt.toTimestamp().toInstant(), ZoneId.systemDefault());
|
||||||
return localDateTime;
|
return localDateTime;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
@@ -762,9 +764,9 @@ public final class ObjectCastUtils {
|
|||||||
}
|
}
|
||||||
} else if (in instanceof String || in instanceof Character) {
|
} else if (in instanceof String || in instanceof Character) {
|
||||||
try {
|
try {
|
||||||
java.sql.Timestamp t = java.sql.Timestamp.valueOf(in.toString());
|
DateTime dt = DateUtil.parse(in.toString());
|
||||||
LocalDateTime localDateTime = LocalDateTime
|
LocalDateTime localDateTime = LocalDateTime
|
||||||
.ofInstant(t.toInstant(), ZoneId.systemDefault());
|
.ofInstant(dt.toTimestamp().toInstant(), ZoneId.systemDefault());
|
||||||
return Timestamp.valueOf(localDateTime);
|
return Timestamp.valueOf(localDateTime);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
Reference in New Issue
Block a user