简体   繁体   English

java date formarter不能将正常的小时格式更改为24小时格式

[英]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. 我有这个javascript值JSON值21/09/2016 13:24:40我想在Java后端中接收它,并将其转换为日期,然后转换为时间戳。

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: 我使用这种格式将String转换为Date如下所示:

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. 我在控制台中打印该值,小时数正确,采用24小时格式。 But when I insert that into the Oracle database the hour is inserted in the normal format not in the 24 hour format. 但是,当我将其插入Oracle数据库时,小时以普通格式而不是24小时格式插入。

I select the date in Oracle like this: 我像这样在Oracle中选择日期:

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: 我尝试使用这种格式将HH更改为hh但是发生了相同的事情:

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

The 24 hour Oracle format is HH24 . 24小时Oracle格式为HH24 Also minutes should be MI . 分钟也应该是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 . 请咨询Oracle日期和时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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