bharathi
bharathi

Reputation: 6271

Convert the XML node value to date

Can I know how to convert the "2016-02-25T07:05:22.0Z" to "yyyyMMddHHmmssS" and then into "yyyyDDDHHmmssS" format.

I have tried the below code:

String test = "2016-02-25T07:05:22.0Z";
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssS");
Date date = formatter.parse(how to pass the test value);
System.out.println(date);
System.out.println(formatter.format(date));

For the above case output value should be "20160560705220".

The functionality is like from one of the application the 20160560705220 will get converted to "yyyyDDDHHmmssS" and then to "'yyyy-MM-dd''T''HH:mm:ss.S''Z'" as passed as response to request soap xml.

  DECLARE rInHeader REFERENCE TO     rEnvXmlNsc.UISInqSubscriberResponse.*:Envelope.*:Header;
              IF rInHeader.*:CESInformation.*:SubscriberContextIdentifier <>   '' THEN
                    SET rOutMember.ct:MemberEffectiveTimestamp =    CAST(CAST(CAST(CAST(rInHeader.*:CESInformation.*:SubscriberContextIdentifier AS DECIMAL) AS CHARACTER) AS TIMESTAMP FORMAT 'yyyyDDDHHmmssS') AS CHARACTER FORMAT 'yyyy-MM-dd''T''HH:mm:ss.S''Z');
              END IF; 

Now I need this part of the code to get converted to "20160560705220" on my end.

Can any one help one this one.

Upvotes: 0

Views: 695

Answers (1)

sgpalit
sgpalit

Reputation: 2686

    String test = "2016-02-25T07:05:22.0Z";
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssS");
    SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.'0Z'");

    Date date = null;
    try
    {
        date = formatter2.parse(test);
    }
    catch (ParseException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(date);
    System.out.println(formatter.format(date));

Upvotes: 1

Related Questions