java - Comparing SQL Dates from various components -


i have created java swing interface has 4 components

spinner      (jxdatepicker)    //get date in format yyyy-mm-dd  spinner_1    (jtimechooser)    //get time in format 00-00-00    spinner_2    (jxdatepicker)    //get date in format yyyy-mm-dd  spinner_3    (jtimechooser)    //get time in format 00-00-00  

all final dates must sql date , sql time , not java.util

i trying create 2 different dates: starting date , ending date

here code:

        calendar startingdate = calendar.getinstance();         startingdate.settime(spinner.getdate());          //this deprecated         //date dt = new date(spinner.getdate().gettime());         //dt.gethours();         //dt.getminutes();         //dt.getseconds();          calendar startingdatetime = calendar.getinstance();                     //this example not point right year,month , day         startingdate.set(startingdate.year, startingdate.month, startingdate.day_of_month, spinner_1.gethours(), spinner_1.getminutes(), spinner_1.getseconds());;          calendar finishingdate = calendar.getinstance();         finishingdate.settime( spinner_2.getdate());          calendar finishingdatetime = calendar.getinstance();                     //same of above         finishingdatetime.set(finishingdate.year, finishingdate.month, finishingdate.day_of_month, spinner_3.gethours(), spinner_3.getminutes(), spinner_3.getseconds());;          if(startingdatetime.equals(finishingdatetime)){             joptionpane.showmessagedialog(null,                     "please insert 2 different dates.",                     "date error",                     joptionpane.error_message);                 return;         }else if(startingdatetime.after(finishingdatetime)){             joptionpane.showmessagedialog(null,                     "please ending date must after starting date.",                     "date error",                     joptionpane.error_message);                 return;                      }else{                      //do                      } 

i create 2 dates , compare them.

many methods deprecated , think solution easy

thank

try this.

simpledateformat dateformat = new simpledateformat("yyyy-mm-dd"); java.util.date startingdate = dateformat.parse(spinner.getdate()); java.util.date finishingdate = dateformat.parse(spinner_2.getdate()); if(endate.before(stdate)) {     //do } else {     //do else } 

if want date , time format, can try.

simpledateformat dateformat = new simpledateformat("yyyy-mm-dd hh:ss:ii"); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -