Drizzy
Drizzy

Reputation: 138

SQL timeStamp format is different on windows and ubuntu

I have a db in mysql in which one column is of timstamp datatype. It stores timstamp in this format yyyy-mm-dd hh-mm-sson both windows and linux. But when i am fetching data from mysql from my java code, it brings data in this format May 11, 2018, 11:35:34 AM on my windows and in this format May 11, 2018 11:35:34 AM on linux ubuntu.

How make timestamp format consistent?

Upvotes: 0

Views: 246

Answers (1)

fvu
fvu

Reputation: 32973

This is caused by a change in behavior in JDK9, where the default formats being used are now those of Unicode CLDR, as explained here:

https://docs.oracle.com/javase/9/intl/internationalization-enhancements-jdk-9.htm#JSINT-GUID-9DCDB41C-A989-4220-8140-DBFB844A0FCA

The article explains one way of changing this behavior, by overriding the java.locale.providers property.

The solution I would prefer (as although more elaborate it also allows for more flexibility) is to always use an explicit formatter for date time values. Eg look here

Upvotes: 1

Related Questions