1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Some more getTimestamp() fixes

This commit is contained in:
Peter Mount
2000-10-17 14:52:01 +00:00
parent d3f6552821
commit f7b89ac5d9
3 changed files with 39 additions and 3 deletions

View File

@ -462,7 +462,23 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
if(s==null)
return null;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// This works, but it's commented out because Michael Stephenson's
// solution is better still:
//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Michael Stephenson's solution:
SimpleDateFormat df = null;
if (s.length()>21 && s.indexOf('.') != -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
} else if (s.length()>19 && s.indexOf('.') == -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:sszzz");
} else if (s.length()>19 && s.indexOf('.') != -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss.SS");
} else if (s.length()>10 && s.length()<=18) {
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
} else {
df = new SimpleDateFormat("yyyy-MM-dd");
}
try {
return new Timestamp(df.parse(s).getTime());