如何使用jsp代码在mysql中将日期格式从yyyy / dd / mm转换为mm / dd / yyyy?

时间:2017-03-08 07:00:39

标签: mysql jsp

我在前端使用了日期选择器,格式为mm / dd / yyyy,我在mysql中选择了日期数据类型,然后如何编写代码,将其从yyyy / dd / mm转换为mm / dd / yyy使用jsp。我试过代码但没有工作请帮助我

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Reg</title>
</head>
<body>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%

String leave_category=request.getParameter("leave"); 
String reason=request.getParameter("reas"); 
String days=request.getParameter("difference"); 
String start_date=request.getParameter("color"); 
String end_date=request.getParameter("color"); 

Class.forName("com.mysql.jdbc.Driver"); 
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root",""); 
Statement st= con.createStatement(); 
ResultSet rs; 
int i=st.executeUpdate("insert into leave_for values ( '"+leave_category+"','"+reason+"','"+days+"','"+start_date+"','"+end_date+"')"); 
out.println("Registered"); 
response.sendRedirect("LeaveForm1.jsp");


%>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

试试这个:

select str_to_date("03/02/2009","%d/%m/%Y");

它会给出:

2009-02-03