java - Error when trying to parse ending date -


okay i'm struggling understand i'd in situation. have current date specified gets date specific action performed, , need specifify finish date, method know when finish processing.

public void process() {     currentdate = getcurrentdate();      string datestart = lotterystart;     string datestop = getcurrentdate().tostring();      simpledateformat format = new simpledateformat("dd/mm/yyyy hh:mm");  date d1 = null; date d2 = null;  try {     d1 = format.parse(datestart);     d2 = format.parse(datestop);      datetime dt1 = new datetime(d1);     //datetime dt2 = dt1.plusminutes(10);     datetime dt2 = new datetime(d2);     sendmessage(integer.tostring(minutes.minutesbetween(dt1, dt2).getminutes() % 60));     if (dt2 == dt1.plusminutes(1)) {     //sendmessage(integer.tostring(minutes.minutesbetween(dt1, dt2).getminutes() % 60));     //if (minutes.minutesbetween(dt1, dt2).getminutes() % 60 == 500) {         durationreached = true;     }      } catch (exception e) { e.printstacktrace(); }  } 

how make end date, specific amount of time in front of starting date? example, if start date 06/10/2013 23:02, end date 06/10/2013 23:05

it's ignoring

if (dt2 == dt1.plusminutes(1)) { 

except time increasing fine fine.

i don't know how i'd go setting ending date. appreciated.

1) datetime immutable, when use dt1.plusminutes(1)then instance dt1 not changed.
new instance of datetime created. so, should assign new instance dt1.

datetime dt1 = new datetime(d1).plusminutes(1); datetime dt2 = new datetime(d2);  

2) don't compare dates ==, should use object::equals(object) instead:

if (dt2.equals(dt1)) { 

edit
there simpler way parse datetime without java.util.date , simpledateformat, with
datetimeformatter , datetimeformat.

datetimeformatter dtf = datetimeformat.forpattern("dd/mm/yyyy hh:mm"); datetime dt1 = dtf.parse(dateasstring); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -