Adding certain minutes to Calender.Minute

Hi,
I want cretain amount of minutes to be added to current time and return the time format in HH:mm:ss (16:04:05). To get this I have following code but this is returning 16:4:5 instead 16:04:05 when minutes and seconds are <10(two digit). It is happening because Calender.Minute gives like that single digit <two digit.
We can do workaround for this by doing some conditions but I would like to check if we have any other nice way of doing.

IDataCursor pipelineCursor = pipeline.getCursor();
String addMin = IDataUtil.getString( pipelineCursor, “addMin” );
pipelineCursor.destroy();

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-mm-dd”);
//sdf.format(cal.getTime());
SimpleDateFormat sdf1 = new SimpleDateFormat(“HH:mm:ss”);
//sdf1.format(cal.getTime());

Calendar now = Calendar.getInstance();
now.add(Calendar.MINUTE,Integer.parseInt(addMin));

// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, “time”, sdf.format(cal.getTime()) );
IDataUtil.put( pipelineCursor_1, “time1”, sdf1.format(cal.getTime()) );
String addTime=String.valueOf(now.get(Calendar.HOUR_OF_DAY))+“:”+String.valueOf(now.get(Calendar.MINUTE))+“:”+String.valueOf(now.get(Calendar.SECOND));
IDataUtil.put( pipelineCursor_1, “hr”, String.valueOf(now.get(Calendar.HOUR_OF_DAY)));
IDataUtil.put( pipelineCursor_1, “min”, String.valueOf(now.get(Calendar.MINUTE)));
IDataUtil.put( pipelineCursor_1, “sec”, String.valueOf(now.get(Calendar.SECOND)));
IDataUtil.put( pipelineCursor_1, “addTime”, addTime );

pipelineCursor_1.destroy();

Thanks,
Kartheek

Is the value of the “time1” var “16:04:05”? It should be.

The value of “addTime” is “16:4:5” because you’re building the string yourself. This should do what you’re looking for:

[highlight=java]
IDataCursor pipelineCursor = pipeline.getCursor();
int addMin = IDataUtil.getInt(pipelineCursor, “addMin”, 0);

SimpleDateFormat sdf1 = new SimpleDateFormat(“HH:mm:ss”);
Calendar now = Calendar.getInstance();
now.add(Calendar.MINUTE, addMin);

IDataUtil.put(pipelineCursor, “time1”, sdf1.format(now.getTime()) );
pipelineCursor.destroy();[/highlight]

Reamon,
Thanks It works…

Thanks,
Kartheek

I just wonder about one of the scenerios…
Ex:
date: 03/13/2009 and time: 23:50:30

Add 15min to the time than time: 00:05:30 but date is still 03/13/2009. In this case throws an error stating passed time or something like this.

any ideas…

Thanks,
Kartheek

I think I got the solution…I am not sure but it is based on which Object you are using. I created another Calendar object and Calendar.getTime() of new object then it is fine…
below is the code…

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String addMin = IDataUtil.getString( pipelineCursor, “MinInterval” );
pipelineCursor.destroy();

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/dd”);

SimpleDateFormat sdf1 = new SimpleDateFormat(“HH:mm:ss”);

String addTime;
String schedDate;
try{
int min=Integer.parseInt(addMin);
Calendar now = Calendar.getInstance();
now.add(Calendar.MINUTE,min);

schedDate = sdf.format(now.getTime());
addTime=sdf1.format(now.getTime());

}catch (Exception e){
throw new ServiceException(e);
}
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, “schedDate”, schedDate );
IDataUtil.put( pipelineCursor_1, “schedTime”, addTime );

pipelineCursor_1.destroy();

Thanks,
Kartheek