on 10-22-2009 12:21 PM
Hi All
How can i convert string to date. The r/3 is returning date as string but when i want to display it in portal i need the calendar logo so the date can be changed how can i convert this string to date.
Thanks in advance
Maybe you can change the output data type of your RFC to date.
If not, you have to get the value of the RFC in a string bult-in type context attribute and code manually a conversion from String to Date. Then store the Date value converted to other context attribute and map it to tour InputField UI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use following code.
import java.util.*;
import java.text.*;
String str_date="11-June-07";
DateFormat formatter ;
Date date ;
formatter = new SimpleDateFormat("dd-MMM-yy"); " Here give the format in which you want your output.
date = (Date)formatter.parse(str_date);
I hope it helps.
Regards,
Rohit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The reason you are getting classCastException is due to invalid date type. The RFC will return or accept java.sql.Date type as Date, since you are using Rohit's code above you are converting to java.util.Date type. So to avoid classCastException, use the below code which is corrected version of Rohit's code
String str_date="11-June-07";
DateFormat formatter ;
formatter = new SimpleDateFormat("dd-MMM-yy"); // Here give the format in which you want your output.
java.util.Date utilDate = (java.util.Date)formatter.parse(str_date);
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
Above code should work and hope it helps.
NOTE: When working with RFC FM's Dates are handled as java.sql.Date in Java not java.util.Date which is default namespace available in all Java classes.
Praveen
Hi,
use the SimpledateFormat class to parse the date.
SimpleDateFormat sdf=new SimpleDateFormat("dd.MM.yyyy");
Date dte=sdf.parse(dateString);
Regards,
Naga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.