cancel
Showing results for 
Search instead for 
Did you mean: 

how to store a current date into a variable.

Former Member
0 Kudos

hai all,

can any body suggest how to store system date into a variable.

is there any possibility to store day , month and year into different variable.

how to merge three different variable to form a date.

thanks and regards,

risingstar.

Accepted Solutions (1)

Accepted Solutions (1)

srinivas_sistu
Active Contributor
0 Kudos

Hi,

wdContext.CurrentContextElement().setVa_Date(new Date(System.currentTimeMillis()); will set the server's current date.

User Calander function of java, to get day, date, month year etc...

Regards,

SrinivaS

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

If you just want the day, month and year from a system date. You can use the following code:


    Calendar cal = Calendar.getInstance();
    SimpleDateFormat monthFormat= new SimpleDateFormat("MM");
    SimpleDateFormat dayFormat= new SimpleDateFormat("dd");
    SimpleDateFormat yearFormat= new SimpleDateFormat("yyyy");
    SimpleDateFormat dateFormat= new SimpleDateFormat("dd-MM-yyyy");
    String month = monthFormat.format(cal.getTime());
    String day = dayFormat.format(cal.getTime());
    String year = yearFormat.format(cal.getTime());

    String dateString = day + "-" + month + "-" + year
    Date currDate = (Date) dateFormat.parse(dateString);

Regards,

kartikaye

Former Member
0 Kudos

For current date use the following code:

java.util.Date currDate = Calendar.getInstance().getTime();

Date todaysDate = new Date(currDate.getTime());

is there any possibility to store day , month and year into different variable.

For setting specific date use thic code Eg June 1 2009:

Calendar cal = Calendar.getInstance();

cal.clear();

cal.set(Calendar.YEAR, 2009);

cal.set(Calendar.MONTH, 5); //pass 5 for june (i.e normal month no-1)

cal.set(Calendar.DATE, 1);

//Create instance of java.sql.Date

java.sql.Date begDa = new java.sql.Date(cal.getTimeInMillis());

Use java.sql.Date if you to pass to RFC or us can use util.Date

Edited by: Santhosh Edla on Jun 11, 2009 3:40 PM

Former Member
0 Kudos

Hi,

You can get the current year, month, date as below using Calandar object.

Date myDate = new Date();

Calendar cal = Calendar.getInstance();

cal.setTime(myDate);

int year = cal.get(Calendar.YEAR);

Regards,

Charan