Get the dd-MM-yyyy format of date in Java (JSP)
up vote
2
down vote
favorite
I'm using an input=date calendar, and i want to output this format of date (dd-MM-yyyy) in my jsp ,when i choose the 2nd day of april 2014 in the calendar given by the input ,I have this output in my jsp:
Wed Apr 02 00:00:00 WET 2014
Here you are the code:
index.jsp :
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="datepickeer" action="showdates.jsp" method="POST">
<table>
<tr><td>Date début :</td> <td><input type = "date" name = "datedebut">
</td><tr>
<tr><td><input type = "submit" name = "submit" value = "submit">
</td></tr>
</table>
</form>
</body>
</html>
showdates.jsp :
<%@ page import="java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
out.println(result);
%>
</body>
</html>
What's the problem with my code?
java date date-format simpledateformat
add a comment |
up vote
2
down vote
favorite
I'm using an input=date calendar, and i want to output this format of date (dd-MM-yyyy) in my jsp ,when i choose the 2nd day of april 2014 in the calendar given by the input ,I have this output in my jsp:
Wed Apr 02 00:00:00 WET 2014
Here you are the code:
index.jsp :
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="datepickeer" action="showdates.jsp" method="POST">
<table>
<tr><td>Date début :</td> <td><input type = "date" name = "datedebut">
</td><tr>
<tr><td><input type = "submit" name = "submit" value = "submit">
</td></tr>
</table>
</form>
</body>
</html>
showdates.jsp :
<%@ page import="java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
out.println(result);
%>
</body>
</html>
What's the problem with my code?
java date date-format simpledateformat
Please do as this answer.
– Tiny
Apr 10 '14 at 9:46
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm using an input=date calendar, and i want to output this format of date (dd-MM-yyyy) in my jsp ,when i choose the 2nd day of april 2014 in the calendar given by the input ,I have this output in my jsp:
Wed Apr 02 00:00:00 WET 2014
Here you are the code:
index.jsp :
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="datepickeer" action="showdates.jsp" method="POST">
<table>
<tr><td>Date début :</td> <td><input type = "date" name = "datedebut">
</td><tr>
<tr><td><input type = "submit" name = "submit" value = "submit">
</td></tr>
</table>
</form>
</body>
</html>
showdates.jsp :
<%@ page import="java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
out.println(result);
%>
</body>
</html>
What's the problem with my code?
java date date-format simpledateformat
I'm using an input=date calendar, and i want to output this format of date (dd-MM-yyyy) in my jsp ,when i choose the 2nd day of april 2014 in the calendar given by the input ,I have this output in my jsp:
Wed Apr 02 00:00:00 WET 2014
Here you are the code:
index.jsp :
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="datepickeer" action="showdates.jsp" method="POST">
<table>
<tr><td>Date début :</td> <td><input type = "date" name = "datedebut">
</td><tr>
<tr><td><input type = "submit" name = "submit" value = "submit">
</td></tr>
</table>
</form>
</body>
</html>
showdates.jsp :
<%@ page import="java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
out.println(result);
%>
</body>
</html>
What's the problem with my code?
java date date-format simpledateformat
java date date-format simpledateformat
edited Apr 10 '14 at 9:15
Tiny
8,21375254483
8,21375254483
asked Apr 10 '14 at 9:01
Nihad KH
542211
542211
Please do as this answer.
– Tiny
Apr 10 '14 at 9:46
add a comment |
Please do as this answer.
– Tiny
Apr 10 '14 at 9:46
Please do as this answer.
– Tiny
Apr 10 '14 at 9:46
Please do as this answer.
– Tiny
Apr 10 '14 at 9:46
add a comment |
4 Answers
4
active
oldest
votes
up vote
2
down vote
accepted
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat AppDateFormat = new SimpleDateFormat("dd-MM-yyyy");
out.println(AppDateFormat.format(result));
3
Stack Overflow is a Q&A site wherein everyone upvotes each other upon agreement. Stack Overflow is not an old fashioned discussion forum wherein everyone repeats each other into an undigestable mess upon agreement.
– BalusC
May 12 '14 at 10:24
add a comment |
up vote
5
down vote
Try this -
<%
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat newFormater = new SimpleDateFormat("dd-MM-yyyy");
out.println(newFormater.format(result));
%>
@Subharajyoti Majumde : I tried it and the output is : 2014-04-02 instead of the format i want : 02-04-2014
– Nihad KH
Apr 10 '14 at 9:21
Opps.... In that case - create new Formatternew SimpleDateFormat("dd-MM-yyyy");
and format the parsed date
– Subhrajyoti Majumder
Apr 10 '14 at 9:32
@Subharajyoti Majumde : I did this: <%String dateStr = request.getParameter("datedebut"); SimpleDateFormat formater2= new SimpleDateFormat("dd-MM-yyyy"); Date result = formater2.parse(dateStr); out.println(result);%> ,I choose the second of april 2014 and I got this output: Wed Oct 05 00:00:00 WET 7
– Nihad KH
Apr 10 '14 at 9:37
Answer updated...
– Subhrajyoti Majumder
Apr 10 '14 at 9:39
thank you so muuuuuuch you just save my life yeey wish u all the best
– Nihad KH
Apr 10 '14 at 9:48
|
show 1 more comment
up vote
0
down vote
You have converted the input from index.jsp into Date using formater.parse. Now to show it on the output in showdates.jsp, you have to again convert into String using formater.format(result) to yyyy-MM-dd. Actually what you are doing is correct. Whatever you get from input you should first parse and then print because you will be sure that the input which came fits into what you require. Use this.
Date result = formater.parse(dateStr);
SimpleDateFormat formaterForOut = new SimpleDateFormat("dd-MM-yyyy");
String resultString = formaterForOut.format(result);
out.println(resultString);
I tried your code and I got the same output : Wed Apr 02 00:00:00 WET 2014
– Nihad KH
Apr 10 '14 at 9:27
add a comment |
up vote
0
down vote
<%
String dateStr = request.getParameter("datedebut");
java.text.SimpleDateFormat oldFormater = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date resultInDate = oldFormater.parse(dateStr);
java.text.SimpleDateFormat newFormater = new SimpleDateFormat("dd-mm-yyyy");
String resultInString = newFormater.format(resultInDate);
out.println(resultInDate); // Wed Apr 02 00:00:00 WET 2014
out.println(resultInString); // 02-04-2014
/* convert String resultInString into java.sql.Date resultInDateSql */
java.sql.Date resultInDateSql = java.sql.Date.valueOf(resultInString);
/* set in query sql */
preparedStatement.setDate(1, resultInDateSql);
%>
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat AppDateFormat = new SimpleDateFormat("dd-MM-yyyy");
out.println(AppDateFormat.format(result));
3
Stack Overflow is a Q&A site wherein everyone upvotes each other upon agreement. Stack Overflow is not an old fashioned discussion forum wherein everyone repeats each other into an undigestable mess upon agreement.
– BalusC
May 12 '14 at 10:24
add a comment |
up vote
2
down vote
accepted
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat AppDateFormat = new SimpleDateFormat("dd-MM-yyyy");
out.println(AppDateFormat.format(result));
3
Stack Overflow is a Q&A site wherein everyone upvotes each other upon agreement. Stack Overflow is not an old fashioned discussion forum wherein everyone repeats each other into an undigestable mess upon agreement.
– BalusC
May 12 '14 at 10:24
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat AppDateFormat = new SimpleDateFormat("dd-MM-yyyy");
out.println(AppDateFormat.format(result));
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat AppDateFormat = new SimpleDateFormat("dd-MM-yyyy");
out.println(AppDateFormat.format(result));
answered Apr 10 '14 at 10:15
user3091530
4081619
4081619
3
Stack Overflow is a Q&A site wherein everyone upvotes each other upon agreement. Stack Overflow is not an old fashioned discussion forum wherein everyone repeats each other into an undigestable mess upon agreement.
– BalusC
May 12 '14 at 10:24
add a comment |
3
Stack Overflow is a Q&A site wherein everyone upvotes each other upon agreement. Stack Overflow is not an old fashioned discussion forum wherein everyone repeats each other into an undigestable mess upon agreement.
– BalusC
May 12 '14 at 10:24
3
3
Stack Overflow is a Q&A site wherein everyone upvotes each other upon agreement. Stack Overflow is not an old fashioned discussion forum wherein everyone repeats each other into an undigestable mess upon agreement.
– BalusC
May 12 '14 at 10:24
Stack Overflow is a Q&A site wherein everyone upvotes each other upon agreement. Stack Overflow is not an old fashioned discussion forum wherein everyone repeats each other into an undigestable mess upon agreement.
– BalusC
May 12 '14 at 10:24
add a comment |
up vote
5
down vote
Try this -
<%
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat newFormater = new SimpleDateFormat("dd-MM-yyyy");
out.println(newFormater.format(result));
%>
@Subharajyoti Majumde : I tried it and the output is : 2014-04-02 instead of the format i want : 02-04-2014
– Nihad KH
Apr 10 '14 at 9:21
Opps.... In that case - create new Formatternew SimpleDateFormat("dd-MM-yyyy");
and format the parsed date
– Subhrajyoti Majumder
Apr 10 '14 at 9:32
@Subharajyoti Majumde : I did this: <%String dateStr = request.getParameter("datedebut"); SimpleDateFormat formater2= new SimpleDateFormat("dd-MM-yyyy"); Date result = formater2.parse(dateStr); out.println(result);%> ,I choose the second of april 2014 and I got this output: Wed Oct 05 00:00:00 WET 7
– Nihad KH
Apr 10 '14 at 9:37
Answer updated...
– Subhrajyoti Majumder
Apr 10 '14 at 9:39
thank you so muuuuuuch you just save my life yeey wish u all the best
– Nihad KH
Apr 10 '14 at 9:48
|
show 1 more comment
up vote
5
down vote
Try this -
<%
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat newFormater = new SimpleDateFormat("dd-MM-yyyy");
out.println(newFormater.format(result));
%>
@Subharajyoti Majumde : I tried it and the output is : 2014-04-02 instead of the format i want : 02-04-2014
– Nihad KH
Apr 10 '14 at 9:21
Opps.... In that case - create new Formatternew SimpleDateFormat("dd-MM-yyyy");
and format the parsed date
– Subhrajyoti Majumder
Apr 10 '14 at 9:32
@Subharajyoti Majumde : I did this: <%String dateStr = request.getParameter("datedebut"); SimpleDateFormat formater2= new SimpleDateFormat("dd-MM-yyyy"); Date result = formater2.parse(dateStr); out.println(result);%> ,I choose the second of april 2014 and I got this output: Wed Oct 05 00:00:00 WET 7
– Nihad KH
Apr 10 '14 at 9:37
Answer updated...
– Subhrajyoti Majumder
Apr 10 '14 at 9:39
thank you so muuuuuuch you just save my life yeey wish u all the best
– Nihad KH
Apr 10 '14 at 9:48
|
show 1 more comment
up vote
5
down vote
up vote
5
down vote
Try this -
<%
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat newFormater = new SimpleDateFormat("dd-MM-yyyy");
out.println(newFormater.format(result));
%>
Try this -
<%
String dateStr = request.getParameter("datedebut");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
Date result = formater.parse(dateStr);
SimpleDateFormat newFormater = new SimpleDateFormat("dd-MM-yyyy");
out.println(newFormater.format(result));
%>
edited Aug 23 '14 at 9:07
answered Apr 10 '14 at 9:04
Subhrajyoti Majumder
33.1k105790
33.1k105790
@Subharajyoti Majumde : I tried it and the output is : 2014-04-02 instead of the format i want : 02-04-2014
– Nihad KH
Apr 10 '14 at 9:21
Opps.... In that case - create new Formatternew SimpleDateFormat("dd-MM-yyyy");
and format the parsed date
– Subhrajyoti Majumder
Apr 10 '14 at 9:32
@Subharajyoti Majumde : I did this: <%String dateStr = request.getParameter("datedebut"); SimpleDateFormat formater2= new SimpleDateFormat("dd-MM-yyyy"); Date result = formater2.parse(dateStr); out.println(result);%> ,I choose the second of april 2014 and I got this output: Wed Oct 05 00:00:00 WET 7
– Nihad KH
Apr 10 '14 at 9:37
Answer updated...
– Subhrajyoti Majumder
Apr 10 '14 at 9:39
thank you so muuuuuuch you just save my life yeey wish u all the best
– Nihad KH
Apr 10 '14 at 9:48
|
show 1 more comment
@Subharajyoti Majumde : I tried it and the output is : 2014-04-02 instead of the format i want : 02-04-2014
– Nihad KH
Apr 10 '14 at 9:21
Opps.... In that case - create new Formatternew SimpleDateFormat("dd-MM-yyyy");
and format the parsed date
– Subhrajyoti Majumder
Apr 10 '14 at 9:32
@Subharajyoti Majumde : I did this: <%String dateStr = request.getParameter("datedebut"); SimpleDateFormat formater2= new SimpleDateFormat("dd-MM-yyyy"); Date result = formater2.parse(dateStr); out.println(result);%> ,I choose the second of april 2014 and I got this output: Wed Oct 05 00:00:00 WET 7
– Nihad KH
Apr 10 '14 at 9:37
Answer updated...
– Subhrajyoti Majumder
Apr 10 '14 at 9:39
thank you so muuuuuuch you just save my life yeey wish u all the best
– Nihad KH
Apr 10 '14 at 9:48
@Subharajyoti Majumde : I tried it and the output is : 2014-04-02 instead of the format i want : 02-04-2014
– Nihad KH
Apr 10 '14 at 9:21
@Subharajyoti Majumde : I tried it and the output is : 2014-04-02 instead of the format i want : 02-04-2014
– Nihad KH
Apr 10 '14 at 9:21
Opps.... In that case - create new Formatter
new SimpleDateFormat("dd-MM-yyyy");
and format the parsed date– Subhrajyoti Majumder
Apr 10 '14 at 9:32
Opps.... In that case - create new Formatter
new SimpleDateFormat("dd-MM-yyyy");
and format the parsed date– Subhrajyoti Majumder
Apr 10 '14 at 9:32
@Subharajyoti Majumde : I did this: <%String dateStr = request.getParameter("datedebut"); SimpleDateFormat formater2= new SimpleDateFormat("dd-MM-yyyy"); Date result = formater2.parse(dateStr); out.println(result);%> ,I choose the second of april 2014 and I got this output: Wed Oct 05 00:00:00 WET 7
– Nihad KH
Apr 10 '14 at 9:37
@Subharajyoti Majumde : I did this: <%String dateStr = request.getParameter("datedebut"); SimpleDateFormat formater2= new SimpleDateFormat("dd-MM-yyyy"); Date result = formater2.parse(dateStr); out.println(result);%> ,I choose the second of april 2014 and I got this output: Wed Oct 05 00:00:00 WET 7
– Nihad KH
Apr 10 '14 at 9:37
Answer updated...
– Subhrajyoti Majumder
Apr 10 '14 at 9:39
Answer updated...
– Subhrajyoti Majumder
Apr 10 '14 at 9:39
thank you so muuuuuuch you just save my life yeey wish u all the best
– Nihad KH
Apr 10 '14 at 9:48
thank you so muuuuuuch you just save my life yeey wish u all the best
– Nihad KH
Apr 10 '14 at 9:48
|
show 1 more comment
up vote
0
down vote
You have converted the input from index.jsp into Date using formater.parse. Now to show it on the output in showdates.jsp, you have to again convert into String using formater.format(result) to yyyy-MM-dd. Actually what you are doing is correct. Whatever you get from input you should first parse and then print because you will be sure that the input which came fits into what you require. Use this.
Date result = formater.parse(dateStr);
SimpleDateFormat formaterForOut = new SimpleDateFormat("dd-MM-yyyy");
String resultString = formaterForOut.format(result);
out.println(resultString);
I tried your code and I got the same output : Wed Apr 02 00:00:00 WET 2014
– Nihad KH
Apr 10 '14 at 9:27
add a comment |
up vote
0
down vote
You have converted the input from index.jsp into Date using formater.parse. Now to show it on the output in showdates.jsp, you have to again convert into String using formater.format(result) to yyyy-MM-dd. Actually what you are doing is correct. Whatever you get from input you should first parse and then print because you will be sure that the input which came fits into what you require. Use this.
Date result = formater.parse(dateStr);
SimpleDateFormat formaterForOut = new SimpleDateFormat("dd-MM-yyyy");
String resultString = formaterForOut.format(result);
out.println(resultString);
I tried your code and I got the same output : Wed Apr 02 00:00:00 WET 2014
– Nihad KH
Apr 10 '14 at 9:27
add a comment |
up vote
0
down vote
up vote
0
down vote
You have converted the input from index.jsp into Date using formater.parse. Now to show it on the output in showdates.jsp, you have to again convert into String using formater.format(result) to yyyy-MM-dd. Actually what you are doing is correct. Whatever you get from input you should first parse and then print because you will be sure that the input which came fits into what you require. Use this.
Date result = formater.parse(dateStr);
SimpleDateFormat formaterForOut = new SimpleDateFormat("dd-MM-yyyy");
String resultString = formaterForOut.format(result);
out.println(resultString);
You have converted the input from index.jsp into Date using formater.parse. Now to show it on the output in showdates.jsp, you have to again convert into String using formater.format(result) to yyyy-MM-dd. Actually what you are doing is correct. Whatever you get from input you should first parse and then print because you will be sure that the input which came fits into what you require. Use this.
Date result = formater.parse(dateStr);
SimpleDateFormat formaterForOut = new SimpleDateFormat("dd-MM-yyyy");
String resultString = formaterForOut.format(result);
out.println(resultString);
edited Apr 10 '14 at 9:48
answered Apr 10 '14 at 9:20
bgth
368314
368314
I tried your code and I got the same output : Wed Apr 02 00:00:00 WET 2014
– Nihad KH
Apr 10 '14 at 9:27
add a comment |
I tried your code and I got the same output : Wed Apr 02 00:00:00 WET 2014
– Nihad KH
Apr 10 '14 at 9:27
I tried your code and I got the same output : Wed Apr 02 00:00:00 WET 2014
– Nihad KH
Apr 10 '14 at 9:27
I tried your code and I got the same output : Wed Apr 02 00:00:00 WET 2014
– Nihad KH
Apr 10 '14 at 9:27
add a comment |
up vote
0
down vote
<%
String dateStr = request.getParameter("datedebut");
java.text.SimpleDateFormat oldFormater = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date resultInDate = oldFormater.parse(dateStr);
java.text.SimpleDateFormat newFormater = new SimpleDateFormat("dd-mm-yyyy");
String resultInString = newFormater.format(resultInDate);
out.println(resultInDate); // Wed Apr 02 00:00:00 WET 2014
out.println(resultInString); // 02-04-2014
/* convert String resultInString into java.sql.Date resultInDateSql */
java.sql.Date resultInDateSql = java.sql.Date.valueOf(resultInString);
/* set in query sql */
preparedStatement.setDate(1, resultInDateSql);
%>
add a comment |
up vote
0
down vote
<%
String dateStr = request.getParameter("datedebut");
java.text.SimpleDateFormat oldFormater = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date resultInDate = oldFormater.parse(dateStr);
java.text.SimpleDateFormat newFormater = new SimpleDateFormat("dd-mm-yyyy");
String resultInString = newFormater.format(resultInDate);
out.println(resultInDate); // Wed Apr 02 00:00:00 WET 2014
out.println(resultInString); // 02-04-2014
/* convert String resultInString into java.sql.Date resultInDateSql */
java.sql.Date resultInDateSql = java.sql.Date.valueOf(resultInString);
/* set in query sql */
preparedStatement.setDate(1, resultInDateSql);
%>
add a comment |
up vote
0
down vote
up vote
0
down vote
<%
String dateStr = request.getParameter("datedebut");
java.text.SimpleDateFormat oldFormater = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date resultInDate = oldFormater.parse(dateStr);
java.text.SimpleDateFormat newFormater = new SimpleDateFormat("dd-mm-yyyy");
String resultInString = newFormater.format(resultInDate);
out.println(resultInDate); // Wed Apr 02 00:00:00 WET 2014
out.println(resultInString); // 02-04-2014
/* convert String resultInString into java.sql.Date resultInDateSql */
java.sql.Date resultInDateSql = java.sql.Date.valueOf(resultInString);
/* set in query sql */
preparedStatement.setDate(1, resultInDateSql);
%>
<%
String dateStr = request.getParameter("datedebut");
java.text.SimpleDateFormat oldFormater = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date resultInDate = oldFormater.parse(dateStr);
java.text.SimpleDateFormat newFormater = new SimpleDateFormat("dd-mm-yyyy");
String resultInString = newFormater.format(resultInDate);
out.println(resultInDate); // Wed Apr 02 00:00:00 WET 2014
out.println(resultInString); // 02-04-2014
/* convert String resultInString into java.sql.Date resultInDateSql */
java.sql.Date resultInDateSql = java.sql.Date.valueOf(resultInString);
/* set in query sql */
preparedStatement.setDate(1, resultInDateSql);
%>
edited 18 hours ago
answered 20 hours ago
antelove
62737
62737
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22983392%2fget-the-dd-mm-yyyy-format-of-date-in-java-jsp%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Please do as this answer.
– Tiny
Apr 10 '14 at 9:46