saleemkhan
asked on
how to convert date into dd mon yyyy format
hi all,
i have a problem in date format i am using date like below .
<%java.util.Date date = new java.util.Date();%>
i am inserting date into a table and its storing like this
insert into tablename (d_date) values (date)
and its inserting date like below
Sun Oct 19 09:05:45 GMT+03:00 2003
i want to fetch date in dd mon yyyy format.
with this format i want to make a select query.i struck with the format conversion.
how to do this.
waiting for expert solution.
i have a problem in date format i am using date like below .
<%java.util.Date date = new java.util.Date();%>
i am inserting date into a table and its storing like this
insert into tablename (d_date) values (date)
and its inserting date like below
Sun Oct 19 09:05:45 GMT+03:00 2003
i want to fetch date in dd mon yyyy format.
with this format i want to make a select query.i struck with the format conversion.
how to do this.
waiting for expert solution.
ASKER
Hi,
zonebit,
yes you are right i am fetching date from database only.
i just go throgh the link u sent me.i couldnt work it out
can u help me
convert
Sun Oct 19 09:05:45 GMT+03:00 2003
to
dd mon yyyy
waiting for expert solution.
zonebit,
yes you are right i am fetching date from database only.
i just go throgh the link u sent me.i couldnt work it out
can u help me
convert
Sun Oct 19 09:05:45 GMT+03:00 2003
to
dd mon yyyy
waiting for expert solution.
I don't really program java but I think this should work.
import java.text.DateFormat;
import java.text.SimpleDateFormat ;
// Select the date from the database and store it in a Date variable called yourDate //
String tPattern = "dd MMM yyyy";
SimpleDateFormat sdf = DateFormat.getDateInstance ();
sdf.applyPattern(tPattern) ;
String formattedDate = sdf.format(yourDate);
import java.text.DateFormat;
import java.text.SimpleDateFormat
// Select the date from the database and store it in a Date variable called yourDate //
String tPattern = "dd MMM yyyy";
SimpleDateFormat sdf = DateFormat.getDateInstance
sdf.applyPattern(tPattern)
String formattedDate = sdf.format(yourDate);
ASKER
i tried your comment,
i am getting error here
SimpleDateFormat sdf = DateFormat.getDateInstance ();
type mismatch cannot convert from java.text.dateformat to java.text.simpledateformat
i am getting error here
SimpleDateFormat sdf = DateFormat.getDateInstance
type mismatch cannot convert from java.text.dateformat to java.text.simpledateformat
We'll try this next:
String tPattern = "dd MMM yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(tPattern) ;
sdf.applyPattern(tPattern) ;
String formattedDate = sdf.format(yourDate);
String tPattern = "dd MMM yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(tPattern)
sdf.applyPattern(tPattern)
String formattedDate = sdf.format(yourDate);
ASKER
i am getting error
Error 500: Server caught unhandled exception from servlet [JSP 1.2 Processor]: Cannot format given Object as a Date
String yourDate=null;
String tPattern = "dd MMM yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(tPattern) ;
sdf.applyPattern(tPattern) ;
String formattedDate =" ";
if (rs_register.next())
{
yourDate=rs_register.getSt ring("regi ster_date" );
}
formattedDate=sdf.format(y ourDate);
out.print(formattedDate);
Error 500: Server caught unhandled exception from servlet [JSP 1.2 Processor]: Cannot format given Object as a Date
String yourDate=null;
String tPattern = "dd MMM yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(tPattern)
sdf.applyPattern(tPattern)
String formattedDate =" ";
if (rs_register.next())
{
yourDate=rs_register.getSt
}
formattedDate=sdf.format(y
out.print(formattedDate);
saleem,
yourDate needs to be a Date object, not a String object.
yourDate needs to be a Date object, not a String object.
ASKER
i tried like this,
Date yourdate=null;
i am getting the type date is ambiguous.
Date yourdate=null;
i am getting the type date is ambiguous.
Try:
java.util.Date yourdate = null;
java.util.Date yourdate = null;
ASKER
gettting error here
yourDate=rs_register.getSt
type mismatch cannot convert from java.lang.string to java.lang.date
try:
yourDate = rs_register.getDate("regis ter_date") ;
yourDate = rs_register.getDate("regis
ASKER
i alreday tried
yourDate =rs_gegister.getDate("regi ster_date" )
the database column is varchar2 its not date type
so i have to use
yourDate= rs_register.getString("reg ister_date ");
yourDate =rs_gegister.getDate("regi
the database column is varchar2 its not date type
so i have to use
yourDate= rs_register.getString("reg
right...
yourDate = Date.valueOf(rs_register.g etString(" register_d ate"));
yourDate = Date.valueOf(rs_register.g
ASKER
java compile error
Date cannot be resolved
yourDate = Date.valueOf(rs_register.g etString(" register_d ate"));
Date cannot be resolved
yourDate = Date.valueOf(rs_register.g
yourDate = java.util.Date.valueOf(rs_ register.g etString(" register_d ate"));
ASKER
java compile
the method valueOf java.lang.String is undefined for the type
java.util.Date
yourDate = new java.util.Date(rs_register .getString ("register _date"));
ASKER
java compile
the constructor java.util.date(java.lang.S tring) is deprecated
the constructor java.util.date(java.lang.S
yourDate = DateFormat.getDateTimeInst ance(DateF ormat.FULL , DateFormat.FULL).parse(rs_ register.g etString(" register_d ate"));
ASKER
in compile no erros
when i run jsp and print it i am getting like this
Error 500: Unparseable date: "Sun Oct 19 09:05:45 GMT+03:00 2003"
when i run jsp and print it i am getting like this
Error 500: Unparseable date: "Sun Oct 19 09:05:45 GMT+03:00 2003"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i just tried like this
<%
java.util.Date yourDate = null;
String tParsePattern=null;
tParsePattern = "EEE MMM dd HH:mm:ss zzz yyyy";
SimpleDateFormat ssdf = new SimpleDateFormat(tParsePat tern);
yourDate = ssdf.parse("Sun Oct 19 09:05:45 GMT+03:00 2003");
out.print(yourDate);
%>
i am getting error
Error 500: Unparseable date: "Sun Oct 19 09:05:45 GMT+03:00 2003"
<%
java.util.Date yourDate = null;
String tParsePattern=null;
tParsePattern = "EEE MMM dd HH:mm:ss zzz yyyy";
SimpleDateFormat ssdf = new SimpleDateFormat(tParsePat
yourDate = ssdf.parse("Sun Oct 19 09:05:45 GMT+03:00 2003");
out.print(yourDate);
%>
i am getting error
Error 500: Unparseable date: "Sun Oct 19 09:05:45 GMT+03:00 2003"
According to the SDK JavaDoc, java.util.Date has the following methods:
getYear(), getMonth(), getDay()
You might try this:
java.util.Date date = new java.util.Date();
String s = date.getDay() + " " + date.getMonth() + " " + date.getYear();
But all these methods are deprecated. You should have a look at java.util.Calendar, which would be
java.util.Calendar cal = new java.util.Calendar();
String s = cal.get(Calendar.DAY_OF_MO NTH) + " " + cal.get(Calendar.MONTH)+ " " +cal.get(Calendar.YEAR);
getYear(), getMonth(), getDay()
You might try this:
java.util.Date date = new java.util.Date();
String s = date.getDay() + " " + date.getMonth() + " " + date.getYear();
But all these methods are deprecated. You should have a look at java.util.Calendar, which would be
java.util.Calendar cal = new java.util.Calendar();
String s = cal.get(Calendar.DAY_OF_MO
ASKER
i understand now where i am wrong.
the below code is not working why because in my server where i am executing code the regional setting month value is in arabic.
i executed the same code in a different server where date and time jones are english its working fine.
All the problem is in regional setting and not the jsp code.
tParsePattern = "EEE MMM dd HH:mm:ss zzz yyyy"
SimpleDateFormat ssdf = new SimpleDateFormat(tParsePat tern);
yourDate = ssdf.parse(rs_register.get String("re gister_dat e"));
the below code is not working why because in my server where i am executing code the regional setting month value is in arabic.
i executed the same code in a different server where date and time jones are english its working fine.
All the problem is in regional setting and not the jsp code.
tParsePattern = "EEE MMM dd HH:mm:ss zzz yyyy"
SimpleDateFormat ssdf = new SimpleDateFormat(tParsePat
yourDate = ssdf.parse(rs_register.get
You would be better off selecting the date from the database as is, then formatting it the way you want it using Java. You could use the SimpleDateFormat class to accomplish this.
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html