cancel
Showing results for 
Search instead for 
Did you mean: 

How to Convert String to Date.

Former Member
0 Kudos

Hi Friends

I have one doubt on date convert (String to date)

eleout.setEindt(ele.getConf_Shp_Date());

Here getConf_Shp_Date is string type(java.util.date) and Eindt is date type(java.sql.Date;)

How to Convert String to date. I have to send the date into ECC system this formate (yyyyMMdd). How to set this date format to eleout.setEindt() this method

Can you help me

Regards

Vijay Kalluri

Accepted Solutions (1)

Accepted Solutions (1)

srinivas_sistu
Active Contributor
0 Kudos

Hi,

DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); // Here u can use as per your requirement

try

{

Date today = df.parse("20/12/2005");

System.out.println("Today = " + df.format(today));

} catch (ParseException e)

{

e.printStackTrace();

}

SrinivaS

Former Member
0 Kudos

Hi Cnu,

By using this i am getting error.

DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); // Here u can use as per your requirement

try

{

Date today = df.parse(ele.getConf_Shp_Date());

System.out.println("Today = " + df.format(today));

eleout.setEindt(today);

} catch (ParseException e)

{

e.printStackTrace();

}

Give breff explanation. can you tell me how to write this code.

Regards

Vijay

former_member214651
Active Contributor
0 Kudos

Hi,

Try using this statement in the parse command:

Date today = df.parse(ele.getConf_Shp_Date().toString());

It might be possible that the Conf_Shp_Date is of a different format. Just making it a string.

Regards,

Poojith MV

Former Member
0 Kudos

I have one doubt on date convert (String to date)

eleout.setEindt(ele.getConf_Shp_Date());

Here getConf_Shp_Date is string type(java.util.date) and Eindt is date type(java.sql.Date;)

How to Convert String to date. I have to send the date into ECC system this formate (yyyyMMdd). How to set this date format to eleout.setEindt() this method

Can you give clear code. i am not understand.

Regards

Vijay

former_member214651
Active Contributor
0 Kudos

Hi,

I don't get this point:

Here getConf_Shp_Date is string type(java.util.date)

. Is it a java.util.Date or a String?

If you want the date to be in yyyyMMdd, create a simple type under the Dictionary->SimpleType section of the WD project and set the Datatype as Date and go to the "representation" tab and enter the format as yyyyMMdd

Create a context attribute called "DateNewFormat" and set the type to the simple type created.

If the Conf_Shp_Date is string, u can use the simple date format and convert to a date and set the context attribute "DateNewFormat"

For conversion from util.Date to sql.date refer to the below thread:

/thread/28928 [original link is broken]

use this "DateNewFormat" and set it to the ECC parameter;

eleout.setEindt(wdContext().currentContextElement().getDateNewFormat());

Regards,

Poojith MV

p330068
Active Contributor
0 Kudos

Hi Vijay,

Please use below code might helps

Date dt = null;

SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");

dt = (Date)format.parse(ele.getConf_Shp_Date());

eleout.setEindt(dt);

Also refer to http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Hope it will helps

Regards

Arun

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Plz refer to this code below

import java.util.*;

import java.text.*;

public class StringToDate {

public static void main(String[] args) {

try { String str_date="11-June-07";

DateFormat formatter ;

Date date ;

formatter = new SimpleDateFormat("dd-MMM-yy");

date = (Date)formatter.parse(str_date);

System.out.println("Today is " +date );

} catch (ParseException e)

{System.out.println("Exception :"+e); }

}

}

Regards

Dibyakanta Deo