Skip to content

Commit 7c2e330

Browse files
committed
modify MathUtil date parse
1 parent 06ddc4c commit 7c2e330

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • rdb/rdb-side/src/main/java/com/dtstack/flink/sql/side/rdb/util

rdb/rdb-side/src/main/java/com/dtstack/flink/sql/side/rdb/util/MathUtil.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,15 @@ public static Date getDate(Object obj) {
223223
return null;
224224
}
225225
if (obj instanceof String) {
226-
return Date.valueOf((String) obj);
226+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
227+
try {
228+
return new Date(format.parse((String) obj).getTime());
229+
} catch (ParseException e) {
230+
throw new RuntimeException("String convert to Date fail.");
231+
}
227232
} else if (obj instanceof Timestamp) {
228233
return new Date(((Timestamp) obj).getTime());
229-
}else if (obj instanceof Date){
234+
} else if (obj instanceof Date) {
230235
return (Date) obj;
231236
}
232237
throw new RuntimeException("not support type of " + obj.getClass() + " convert to Date.");
@@ -239,9 +244,9 @@ public static Timestamp getTimestamp(Object obj) {
239244
if (obj instanceof Timestamp) {
240245
return (Timestamp) obj;
241246
} else if (obj instanceof Date) {
242-
return Timestamp.valueOf((String) obj);
247+
return new Timestamp(((Date) obj).getTime());
243248
} else if (obj instanceof String) {
244-
return Timestamp.valueOf((String) obj);
249+
return new Timestamp(getDate(obj).getTime());
245250
}
246251
throw new RuntimeException("not support type of " + obj.getClass() + " convert to Date.");
247252
}

0 commit comments

Comments
 (0)