Skip to content

Commit 1749af8

Browse files
add dateTimeStringToMillis to StringTools
1 parent 0b8b729 commit 1749af8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sqldev/src/main/java/org/utplsql/sqldev/model/StringTools.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
*/
1616
package org.utplsql.sqldev.model;
1717

18+
import java.text.ParseException;
1819
import java.text.SimpleDateFormat;
1920
import java.util.Collections;
2021
import java.util.Date;
2122
import java.util.List;
2223

24+
import org.utplsql.sqldev.exception.GenericRuntimeException;
25+
2326
public class StringTools {
2427
// do not instantiate this class
2528
private StringTools() {
@@ -87,4 +90,17 @@ public static String getSysdate() {
8790
return millisToDateTimeString(System.currentTimeMillis());
8891
}
8992

93+
public static long dateTimeStringToMillis(final String dateTime) {
94+
// handle milliseconds separately since they get lost (rounded) when converted to date
95+
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
96+
Date date;
97+
try {
98+
date = df.parse(dateTime.substring(0, 20));
99+
} catch (ParseException e) {
100+
throw new GenericRuntimeException("cannot parse datetime string " + dateTime + ".", e);
101+
}
102+
long millis = Long.parseLong(dateTime.substring(20, 23));
103+
return date.getTime() + millis;
104+
}
105+
90106
}

0 commit comments

Comments
 (0)