Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet time format hh:mm:ss
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sujitha
time format hh:mm:ss
1 Answer(s)      2 years and a month ago
Posted in : JSP-Servlet


Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?


Advertisement
View Answers

August 28, 2012 at 10:44 AM


Here is a jsp example that fetch the time from the database and display in different format.

<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>

<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from patient");
        SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");
        while(rs.next()){
        java.sql.Time dbSqlTime = rs.getTime("tob");
        java.util.Date date = new java.util.Date(dbSqlTime.getTime());
        out.println(sdf.format(date)+"<br>");
        %>


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com