cancel
Showing results for 
Search instead for 
Did you mean: 

today date

Former Member
0 Kudos

Hi,

I need to pass today's date and time to RFC from webdynpro. how can i get today's date and time and i need the date in mm/dd/yyyy format. is there any standard format for time to pass to ECC system. Please help.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Jyothi,

Find below sample java code, you can use this in WDJ application:-

import java.text.SimpleDateFormat;

import java.util.Calendar;

/**

*

*/

public class Main {

public void convertDateToString() {

//you can use below code:-

Calendar calendar = Calendar.getInstance();//to get the date**

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");//to set the format**

try {

System.out.println("Today: " + dateFormat.format(calendar.getTime()));//to get the current date as per ur format**

} catch (Exception e) {

e.printStackTrace();

}

}

/**

  • @param args the command line arguments

*/

public static void main(String[] args) {

new Main().convertDateToString();

}

}

Hope this may help you.

Deepak!!!

Edited by: Deepak Arora on Jul 16, 2010 8:49 AM

Former Member
0 Kudos

Hi deepak,

actually i have written this code. after formatting the date is of type string, where i want it of type date.

srinivas_sistu
Active Contributor
0 Kudos

Hi Jyothi,

After doing the way Deepak said, you can covert the output String date in to Date using the Java Date.

some thing like this...

java.sql.Date Date1= new Date("StringDate");

or

java.util.Date Date2= new Date("StringDate");

Regards,

SrinivaS

former_member214651
Active Contributor
0 Kudos

Hi,

try this:

java.sql.Date todayDate = new Date(System.currentTimeinMillis()); //For today date
Time timeObject = todayDate.getTime();

Pass this time and date variable to the RFC.

Regards,

Poojith MV

p330068
Active Contributor
0 Kudos

Hi Jyothi,

Ask abap team to accept in other/change date format in backend or accept in string date.



SimpleDateFormat sqlformat = new SimpleDateFormat("MMddyyyy"); 		

GregorianCalendar calendar = new GregorianCalendar();
//java.sql.Date sqlOriginal = new java.sql.Date(calendar.getTimeInMillis());
//System.out.println("Original Date as yyyy-MM-dd ::"+sqlOriginal);

String strdate = sqlformat.format(new java.sql.Date(calendar.getTimeInMillis()));	
try{
	long longDate = Long.valueOf(strdate).longValue();
	java.sql.Date sqlDt = new java.sql.Date(longDate); 
	System.out.println(sqlDt.getTime());
		
}catch(Exception ex)  {
                    System.out.println("Exception"+ex.getLocalizedMessage());
}

It will show as MMddyyy format. send MMddyyyy or yyyy-MM-dd to backend, ask abap team to accept in thse format, they will change it accordingly in backend.

Hope it will helps

Regards

Arun Jaiswal

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks for the answers.

deepak and Srinivas,

i have written the code just the way you said, it gives me the output "Fri Jul 16 00:00:00 GMT 2010". where as i need the date format mm/dd/yyyy.

Poojith,

the code which you have given gives different format. But i need to pass in mm/dd/yyyy format.

Arun,

your code is not working.

p330068
Active Contributor
0 Kudos

Hi Jyothi,

Have you checked/tested it? Now try again..it is working fine from my side.

It is in MMddyyyy or yyyy-MM-dd, backend RFC should accept in this date format or accept it as string format.


public static void DateTest()
{
		
            SimpleDateFormat sqlformat = new SimpleDateFormat("MMddyyyy"); 		
            GregorianCalendar calendar = new GregorianCalendar();
		
            java.sql.Date sqlOriginal = new java.sql.Date(calendar.getTimeInMillis());
           wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("Original Date as yyyy-MM-dd ::"+sqlOriginal);
			
           String strdate = sqlformat.format(new java.sql.Date(calendar.getTimeInMillis()));
		 
           try{
	long longDate = Long.valueOf(strdate).longValue();
	java.sql.Date sqlDtFormatted = new java.sql.Date(longDate); 
wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("Formated Date as MMddyyyy ::"+sqlDtFormatted.getTime());
		
          }catch(Exception ex){
	wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("Exception"+ex.getLocalizedMessage());
          }		
}

Hope it will helps

Regards

Arun Jaiswal

Edited by: Arun Jaiswal on Jul 16, 2010 3:26 PM

Former Member
0 Kudos

Arun,

i had tried the same code. the output is 1970-01-01.

p330068
Active Contributor
0 Kudos

Hi Jyothi,

Please try with

Calendar calendar = Calendar.getInstance(); after removing GregorianCalendar calendar = new GregorianCalendar();

Regards

Arun Jasiwal

Edited by: Arun Jaiswal on Jul 16, 2010 3:54 PM

Former Member
0 Kudos

Arun,

i have changed that part of code. Output is still same

p330068
Active Contributor
0 Kudos

Jyothi,

Then there is problem with in your desktop date setting. Can you please with your colleagues desktops.

Check the Date setting in your desktop might resolved your issue.

Regards

Arun

Edited by: Arun Jaiswal on Jul 16, 2010 4:58 PM