on 05-26-2009 9:18 AM
Hi Experts,
In my component I am getting a date value from back end in DD-MM-YYYY format. Now I need to pass this date to a bapi but it should be a date value of DDMMYYYY format. Now to convert the fomat I am using the following code.:
DateFormat format=null ;
Date date=null ;
format = new SimpleDateFormat("ddmmyyyy");
date = (Date)format.parse(flightdate2);
"flightdate2 is a string variable which contain date value in DDMMYYYY fromat.
By using this code I am getting a run time error: java.lang.ClassCastException.
I am using date of java.sql.date type. Kindly help me to solve this problem.
Regards
Arjun
Hi
You can try the following piece of code :
String convdate = "";
*String str = "26-05-2009";*
* String dtformat = "dd-MM-yyyy";*
* SimpleDateFormat sdf = new SimpleDateFormat(dtformat);*
* try{*
* *
* Date dt = sdf.parse(str);*
* SimpleDateFormat sdf2 = new SimpleDateFormat("ddMMyyyy");*
* convdate = sdf2.format(dt);*
* }catch(Exception e){}*
Hope this will help
Thanks
Ritushree
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
first thing is
format = new SimpleDateFormat("ddmmyyyy");
replace it with
format = new SimpleDateFormat("ddMMyyyy"); and parse requires a string value
so try this below way
java.util.Date d=null;
d=new SimpleDateFormat("yyyy/MM/dd").parse(strDate);
java.sql.Date dt=new Date(d.getTime()); // if you need a SQL date...
Regards,
SrinivaS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In the code I gave you I used yyyy-MM-dd format that is why date is coming in yyyy-MM-dd format, so change that format...
like this
java.util.Date d=null;
d=new SimpleDateFormat("ddMMyyyy").parse(strDate);
java.sql.Date dt=new Date(d.getTime()); // if you need a SQL date...
now you will get the output...
Regards,
SrinivaS
Hi,
If possible give me the below details:
What is the type of date attribute you are getting from backend? & What is the date format of that?
What is the expecting date type of bapi input? & What is the date format of that?
Regards,
Charan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Charan,
What is the type of date attribute you are getting from backend? & What is the date format of that?
I am getting the value of date by executing a bapi and then I am setting the date vaue to an attribute which is of java.sql.date type and the format is yyyy-mm-dd.
What is the expecting date type of bapi input? & What is the date format of that?
The expecting date type is java.sql.date type and the expected format is ddmmyyyy.
Please help.
Regards
Arjun
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.