How to show mysql timestamp/datetime column with AM and PM in JSP/JAVA
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date.*" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.GregorianCalendar" %>
<%@ page import="java.text.*" %>
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date date = format.parse(rs.getString("entry_date_time"));
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
out.print(calendar.get(Calendar.DATE)+"/");
out.print((calendar.get(Calendar.MONTH)+1)+"/");
out.print(calendar.get(Calendar.YEAR)+" ");
out.print(calendar.get(Calendar.HOUR)+":");
out.print(calendar.get(Calendar.MINUTE)+":");
out.print(calendar.get(Calendar.SECOND));
if(calendar.get(Calendar.AM_PM)==0) out.print("AM"); else out.print("PM");
No comments:
Post a Comment