简体   繁体   中英

java date formarter not change the normal hour format to 24 hour format

I have this javascript value JSON value 21/09/2016 13:24:40 I want to receive that in my Java backend and transform it into a date and then into a timestamp.

I created this format:

SimpleDateFormat hourFormat = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss");

And I used that format to convert the String into a Date like this:

initHour = hourFormat.parse((String) datosDTOParseados.get("initHour"));

Timestamp insertHour= new java.sql.Timestamp(initHour.getTime());

I print that value in the console and the hour is right, it's in the 24 hour format. But when I insert that into the Oracle database the hour is inserted in the normal format not in the 24 hour format.

I select the date in Oracle like this:

SELECT TO_CHAR(init_hour, 'dd/mm/yyyy HH:mm:ss') From mytable where id='2';

I tried using this format changing the HH for a hh but the same thing happens:

SimpleDateFormat hourFormat = new SimpleDateFormat("dd/mm/yyyy hh:mm:ss");

The 24 hour Oracle format is HH24 . Also minutes should be MI .

So your code should resemble:

SELECT TO_CHAR(init_hour, 'dd/mm/yyyy hh24:mi:ss') From mytable where id='2';

Consult Oracle Dates and Times .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM