0

i get time field from a database table. But may i know how to convert it into 24 hour minutes and second. simpledateformat("hhmmss") is not working. Is there any other simple java method doing it?

5
Contributors
10
Replies
11
Views
8 Years
Discussion Span
Last Post by masijade
0

Show your code (and use code tags). Also, is it a Date, DateTime, or TimeStamp field in the Database.

Be aware though, that if your calling getDate on the field, that it will return only a Date, the time will be 00:00:00.

0

Show your code (and use code tags). Also, is it a Date, DateTime, or TimeStamp field in the Database.

Be aware though, that if your calling getDate on the field, that it will return only a Date, the time will be 00:00:00.

if i do it this way
String time = x.getTime(1).toString();

will it 24 hour minutes and second in the format 001236 ?

0

Check the doc for SimpleDateFormat. You want to use "HHmmss" instead of "hhmmss".

just tested....it works !! thanks
still need to try it in DB2

0

What is the sql type of the column in your database?
Perhaps you can alter the query in order to format the column and return it as String:

select TO_CHAR(date_col,'DD/MM/YYYY HH24 : MI : SS') from table tbl;

The date_col would be type DATE at the table and when you get the column from the ResultSet you can use: rs.getString();

I think that if it is type TIME then use only: HH24 : MI : SS in the TO_CHAR method

0

... i'd say to have a method that reads the time from thr base then get the HOURs convert it IF needed ex:

public Date convert(Date time){
int mask 12;
if (time <= mask)
time=time+12

0

... i'd say to have a method that reads the time from thr base then get the HOURs convert it IF needed ex:

public Date convert(Date time){
int mask 12;
if (time <= mask)
time=time+12

You declare time as Date and mask as int ?????? Can you please explain what do you mean, because your code doesn't make any sense.

0

Thanks javaAddict.....got your idea........your method works.....

select TO_CHAR(date_col,'DD/MM/YYYY HH24 : MI : SS') from table tbl;

0

... i'd say to have a method that reads the time from thr base then get the HOURs convert it IF needed ex:

public Date convert(Date time){
int mask 12;
if (time <= mask)
time=time+12

This code is not valid and appropriate solutions have already been provided.

0

Don't worry too much about this guy. He has proven on another forum that he doesn't know what he is doing and either just cannot understand what you try to tell him, or simply ignores it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.