Skip to Content
author's profile photo Former Member
Former Member

Convert String in Date format

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Best Answer
    Posted on Nov 26, 2007 at 07:27 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 29, 2007 at 07:30 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Nithya,

      Same question that was asked to Prashil: is there a reason for you posting an identical response (to mine and now Prashil) in this thread, or do you have something more specific to provide to answer this question?

      Regards,

      Joseph

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 04:49 PM

    Hi Guillermo,

    one approach is to use the SimpleDateFormat formatter object (Javadoc herehttp://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html">here>) 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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 24, 2007 at 06:40 AM

    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.....

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 29, 2007 at 01:32 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.