The Java time stuff is bizarre. Timestamps don't have a Timezone you can set...but they do have a Timezone offset...that affects the toString...but that can't be changed...without converting out to a string and back.
Joda-time seems to fix some of these issues, but also would take a bit to implement and I'm sure it'd cause additional issues.
My PostgreSQL and Microsoft SQL JDBC drivers don't add a timezone at all to the returned Timestamp, by MySQL does (or at least an offset that affects the way toString renders the Timestamp). I finally got this solution working:
for (i <- 1 to meta.getColumnCount()) {
rMap += (meta.getColumnLabel(i) -> (ret.getObject(i) match {
case null => null
case ts : Timestamp => {
if(dbDialect == DB_MYSQL) {
//Ensure UTC (MySQL is the only driver that has trouble with this)
val dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss.SSS")
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"))
dateFormatGmt.format(ts)
}
else ts
}
case x:Any => x
}))
}
It's pretty ugly, and is in place because of the non-standard and somewhat buggy/technical debt ridden MySQL JDBC implementation. But it seems to work.