When java.util.Date is parsing "01/01/1901" to a Date objet, JAVA API is converting the date to “01/01/1901 0:08:39” instead of “01/01/1901 0:00:00” and this is happening only for Malaysia time zone. This is happening because in 1901 Malaysia decide to synchronize his time zone with Penang, Malacca and Singapore and for that reason they added 8 minutes and 39 seconds. Java knows this and for that reason is automatically adding minutes and seconds to the date object(Because in Malaysia the hour 00:00:00 doesn’t exist for date 01/01/1991).
Malaysia TZ change:
https://www.timeanddate.com/time/change/malaysia/kuala-lumpur?year=1901
Java Source:
public class SimpleDateFormatExample {
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
// Locale for formatter
Locale malaysianLocale = new Locale("ms", "MY");
// Default date and time format for Malaysia
DateFormat defaultMalaysianFormatter = DateFormat.getDateTimeInstance(
DateFormat.DEFAULT, DateFormat.DEFAULT, malaysianLocale);
// This step is crucial
TimeZone malaysianTimeZone= TimeZone.getTimeZone("Asia/Kuala_Lumpur");
defaultMalaysianFormatter.setTimeZone(malaysianTimeZone);
try {
format.setTimeZone(malaysianTimeZone);
Date a = format.parse("01/01/1901");
String t = defaultMalaysianFormatter.format(a);
System.out.println(t);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
Example java output: 01 Januari 1901 12:08:39 AM.
In Oracle Data base “TO_date” function is not working in the same fashion, we believe that Oracle data base don’t consider the time zone and for that reason it is not retrieving the correct values when send via SQL query.
Oracle Sql Source:
ALTER SESSION SET TIME_ZONE='Asia/Kuala_Lumpur';<br>
select to_date('19010101 00:00:00','YYYYMMDD HH24:MI:SS') from dual;
Example Oracle output: 01-JAN-01 00:00:00
This issues are specific for malaysia Time zone and for 1901 01/01
Why Java and Oracle database are behaving in different fashion?