adding minutes to date

i just want to add 30 minutes to the current date obtained as input

so that i can put it ina loop to use it in a group by clause in oracle

if sme one can help me out in identifying fuctions and classes in java api to do this easily it will be very help full

waiting for it....................

[317 byte] By [bicepjaia] at [2007-11-26 22:05:56]
# 1
Create a GregorianCalendar from the dateuse the method calendar.add(Calendar.MINUTE, 30);convert the GregorianCalendar back to a date
dmbdmba at 2007-7-10 10:50:21 > top of Java-index,Java Essentials,Java Programming...
# 2

I'm sorry, but read the API, that's why it is there.

Date d = new Date(); // starting point

int x = 5; // number of minutes to increment

for (int i = 0; i < 10; i++) { // to increment 10 times

d.setTime(d.getTime() + (x * 60000)); // 60000 milliseconds in one minute

}

And P.S. normally, of course, I would not put all the comments in, but it seemed as though it might be needed in this case.

Edit: And of course, this is only presented as an alternative to the method posted by dmbdmb. Both are valid.

masijade.a at 2007-7-10 10:50:21 > top of Java-index,Java Essentials,Java Programming...
# 3
try this oneDate d = new Date();d.setMinutes(25);
abdulkareema at 2007-7-10 10:50:21 > top of Java-index,Java Essentials,Java Programming...
# 4

> try this one

>

>Date d = new Date();

>d.setMinutes(25);

Nonsense. First because the Date.setMinutes(int minutes) method is deprecated and has been replaced by Calendar.set(Calendar.MINUTE, int minutes), then because it doesn't match OP's requirement (i.e. add 30 minutes to a given date)

Tim - was it a joke or something..?

TimTheEnchantora at 2007-7-10 10:50:21 > top of Java-index,Java Essentials,Java Programming...
# 5

i read about gregorian and calendar classes

but still i find problems

let me show u the code

may be then u can help me,

im trying to query the db for every half an hour

and join details in avector that i pass out from this func

Date tempD;

tempD.valueOf(fromBuff.toString());

Date endD;

endD.valueOf(toBuff.toString());

GregorianCalendar GC = GregorianCalendar(tempD.getyear(),tempD.getMonth(),tempD.getDate(),tempD.getHour(),tempD.getMinute(),tempD.getSecond() );

while(!(Date)GC.equals(endD) || !(Date)GC.after(endD))

{

int index1 = index;

stmntCustDetail.setString(index1++,(Date)GC.toString());

GC.add(GregorianCalendar.MINUTE,30);

stmntCustDetail.setString(index1++,(Date)GC.toString());

stmntCustDetail.setString(index1++,testBed);

GC.add(GregorianCalendar.MINUTE,30);

rs = [statement name].executeQuery();

vc1 = [my owm func](rs);

vc.addAll(vc1);

}

but it shows much error

like in convertibles and cannot resolve symbol

can u help me

bicepjaia at 2007-7-10 10:50:21 > top of Java-index,Java Essentials,Java Programming...
# 6

Date d = // ...

Calendar test = new GregorianCalendar();

test.setTime(d);

test.add(Calendar.MINUTE, 30);

If you want an eye on the compiler error messages, at least do two things: (1) Format your code using the code button, so it's readable (2) quote the precise error message.

OleVVa at 2007-7-10 10:50:21 > top of Java-index,Java Essentials,Java Programming...
# 7
thank u it worked bicepjai
bicepjaia at 2007-7-10 10:50:21 > top of Java-index,Java Essentials,Java Programming...