on 11-22-2007 4:22 PM
Hi.
I need to call a Bapi in java. The Bapi has a import parameter type Date. If , in Java, I've a variable type String. How Can i do the conversion?
Thanks
Hi Guillermo,
Get the BAPI exporting parameter in the String value say "strDate".
Convert this string value in the date using the following code:
SimpleDateFormat sdf = new SimpleDateFormat(strDate);
Date returnDate = sdf.parse(date);
The returnDate will be in the Date format.
Regards,
Prashil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Guillermo,
It appears that a lot of responses to your question are now just repetition...
Has the initial answer provided been of any value for you?
If yes, please consider closing this question and rewarding points for a helpful answer!
Thanks in advance!
Regards,
Joseph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
U can do it by using SimpleDateFormat class.
Try this
String dtstr="4-10-2007";
<b>try</b>{
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
Date dt=sdf.parse(dtstr);
} <b>catch</b>(ParseException ex) {
System.out.println(ex);
}
Hope this will help u
Regards,
Nithya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guillermo another way for converting date format......
Wherever u want to convert date simply call this method..
public String strDate(Date objDate)
{
Calendar objCal=Calendar.getInstance();
objCal.setTime(objDate);
int intDate=objCal.get(Calendar.DATE);
int intMonth=objCal.get(Calendar.MONTH)+1;
int intYear=objCal.get(Calendar.YEAR);
return ""intDate"."intMonth"."+intYear;
}
And another process
StringTokenizer objstr1=new StringTokenizer(objstr,"-");
String year=objstr1.nextToken();
String month=objstr1.nextToken();
String total=objstr1.nextToken();
StringTokenizer objstr3=new StringTokenizer(total," ");
String date=objstr3.nextToken();
String Time=objstr3.nextToken();
String objstr2=""date"/"month"/"+year;
wherever u want to add date simply add objstr2....
Hope this is helpful to u......
Regards...
Sumalatha.....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guillermo,
one approach is to use the <b>SimpleDateFormat</b> formatter object (Javadoc <a href="http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html">here</a>) for your string value.
Here is a sample code:
public class StringToDate
{
public static void main(String[] args)
{
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try
{
Date today = df.parse("01/01/2007");
System.out.println("Jan 1st 2007 = " + df.format(today));
} catch (ParseException e)
{
e.printStackTrace();
}
}
}
Hope this helps.
Regards,
Joseph
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 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.