cancel
Showing results for 
Search instead for 
Did you mean: 

Change date format

Former Member
0 Kudos

Hello,

In SAP XI java mapping I write the code above,

At the moment I received the file name "<b>ABC.0050673686_2007025</b>"

I want to receive file name like that "<b>ABC.0050673686_20070205</b>"

I want to change date from yyyymmd to yyyymmdd

"

public String Change(String a,String Order_Num,Container container){

//Get the Date

Date Today = new java.sql.Date(new java.util.Date().getTime());

//Construct File Name = Macon.Order_NumYearMonthDay

long nowyear = 1900 + Today.getYear();

long nowmonth = 1 + Today.getMonth();

long nowdate = Today.getDate();

String RecieverFilename = "ABC."+ Order_Num +"_" + nowyearnowmonthnowdate;

//Set XI Runtime Parameters

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http:" + "/" + "/" + "sap.com/xi/XI/System/File", "FileName");

conf.put(key, RecieverFilename);

return a;

"

Any idea?

Regards

Elad

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Elad,

The dateformat can be changed using SimpleDateFormat class from java API.

Incude the below code:

import java.text.SimpleDateFormat;

import java.util.Date;

SimpleDateFormat df= new SimpleDateFormat("yyyymmdd");

changedDate = df.format( new Date(date));

Thanks,

Swathi

please offer points if it was useful:-)

Former Member
0 Kudos

Hello all,

This is the code rows that solved the problem (with thank to Dmitry Govberg)

if(nowmonth < 10) nowmonths = "0" + nowmonths;

if(nowdate < 10) nowdates = "0" + nowdates;

Thanks for all your helps

Regards

Elad Peleg

Former Member
0 Kudos

Hi Elad,

To change the date format as per ur reqrmnt, do the following

import java.text.*;

SimpleDateFormat sdf=new SimpleDateFormat("yyyymmdd");

String formatteddate=sdf.format(new Date());//FOR util date

String formatteddate=sdf.format(new Date(System.currentTimeMillis()));//FOR sql date

Regards

Fahad Hamsa

Former Member
0 Kudos

Consider using java.text.DateFormat / java.text.SimpleDateFormat classes for date format conversions.