java - To check time value in JSpinnerand set date in JDateChooser accordingly -
i have 2 jdatechooser(named firstdate , lastdate) , jspinner(named starttime , endtime) in gui.
the scenario is,
1.if open gui current time , set in endtime , currenttime-1 in starttime(the code below),
calendar cal = calendar.getinstance(); cal.add(calendar.hour, -1); date onehourback = cal.gettime(); string timestamp = new simpledateformat("hh:mm:ss").format(onehourback); date date = new simpledateformat("hh:mm:ss").parse(timestamp); starttime.setvalue(date);
2.for both jdatechooser set current date.
3.if current time 00:44:36 (hh:mm:ss), in starttime(jspinner) have set 23:44:36, have set firstdate(jdatechooser) value previous day date instead of current date.
for trying following way,
calendar currenttime = calendar.getinstance(); date curhr = currenttime.gettime(); string curtime = new simpledateformat("hh").format(curhr); int timecheck = integer.parseint(curtime); if(timecheck > 00 && timecheck < 01){ //code set previous day's date }
is way it? or there better way available? please help
you should able use onehourback
date
value value lastdate
jdatechooser
, not has time been rolled back, has date value, example...
calendar cal = calendar.getinstance(); cal.set(calendar.hour_of_day, 0); cal.set(calendar.minute, 44); cal.set(calendar.second, 36); date starttime = cal.gettime(); cal.add(calendar.hour, -1); date endtime = cal.gettime(); system.out.println("starttime = " + starttime); system.out.println("endtime = " + endtime);
outputs...
starttime = thu feb 06 00:44:36 est 2014 endtime = wed feb 05 23:44:36 est 2014
this nice thing calendar
Comments
Post a Comment