Hi, iam new to jsp. actually my problem is with the format of date and time.Datea nad time stored in database are in hh:mm:ss format. but when i am displaying reports, nanoseconds are displaying. please give reason for this.

Recommended Answers

All 9 Replies

hai Neha290791,

could you post the code how you get the date data from database?

so that we try to give a way to solution


    try {

    String query = "select incident_id, assignee_name, open_time from aces_incident_details where incident_id='"+etno+"' and deletion_status is null";  
        rs =stmt.executeQuery(query);
    } catch (java.sql.SQLException e) {

         <table border="1" cellspacing="0" cellpadding="0" width="950" height="23" align="center" >
                <th align="center" width="100">
                <font face = "VERDANA" color = "maroon" size = "2">Problem ID</font></th>
                <font face = "VERDANA" color = "maroon" size = "2">Assignee Name</font></th>
                <th align="center">
                <font face = "VERDANA" color = "maroon" size = "2">Open Time</font></th>
                <font face = "VERDANA" color = "maroon" size = "2"><%= rs.getString(1)%></center></font></TD>
                <font face = "VERDANA" color = "maroon" size = "2"><%= rs.getString(2)%></center></font></TD>
                <font face = "VERDANA" color = "maroon" size = "2"><%= rs.getString(3)%></center></font></TD>




could you post structure of the table?

but you are talking about time column and you are displaying/getting that data by using rs.getString() instead of using rs.getDate()

so i need data type of open_time column of your table.

The datatype for open time is DATETIME.

yeah Neha290791,

if the data type is of date or datetime type

try to do as follows

first get the column value

your_date = rs.getDate("open_time");

then use SimpleDateFormat class to display the time as you like (as follows)

SimpleDateFormat formatter = new SimpleDateFormat("your_format_here");
formatter.format(your_date);  // returns string then display it whareever you want 

check it once and let me know the status

happy coding

hey, i tried but only date is displying with this format..

What should be the datatype for your_date?


java.sql.Time or java.sql.Date both are perfect(as of my knowledge)

but in this case you go for java.sql.Time
try like this

java.sql.Time t = rs.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.format(t)  // return string  

check it once

note : pls post output too incase if you haven't got the output as you expected


please mark it solved if you got correct answer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.