Java.util.Date vs Java.sql.Date - Date value differs -


i have oracle database contains field w_planned_date: 19/03/2013 10:55:00 (date)

in java put value variable:

date dtebeginorwaitingitem = orwaitinglist.getwplanneddate();  value: 2013-03-19 

now, happend time? need fill schedulecomponent of primefaces. how can full date , time value

eventresourceavailperday.addevent(new defaultscheduleevent(reason, dtebeginorwaitingitem, dteendorwaitingitem, "waitingitem")); 

this method puts event @ 12:00 pm there no other time or time 00:00:00

i know how use calendar class lets me set date, time seems empty in database view have date time value.

mybean

import java.util.date; @managedbean(name="schedulecontroller") @sessionscoped public class schedulecontroller implements serializable {  private date dtebeginorwaitingitem, dteendorwaitingitem;  //methods try     {         //eventwaitinglist.clear();         orwaitinglistdao orwaitinglistdao = new orwaitinglistdaoimpl();         waitingevents = orwaitinglistdao.getorwaitinglistkeysbyresource(rkey);         int = 0;         iterator<orwaitinglist> it2 = waitingevents.iterator();         while (it2.hasnext())          {             orwaitinglist = it2.next();             dtebeginorwaitingitem = (date) orwaitinglist.getwplanneddate();             dteendorwaitingitem = orwaitinglist.getwplanneddate();             //dteendorwaitingitem = orwaitinglist.getwplanneddate();             reason = orwaitinglist.getwdescription();             eventresourceavailperday.addevent(new defaultscheduleevent(reason, dtebeginorwaitingitem, dteendorwaitingitem, "waitingitem"));              += 1;             system.out.println("eventwaiting: " + + " " + dtebeginorwaitingitem + " " + dteendorwaitingitem + " " + reason);         }      }     catch(java.util.emptystackexception ex)     {         system.out.println(ex.getmessage());     } 

working update: bean:

try     {         //eventwaitinglist.clear();         orwaitinglistdao orwaitinglistdao = new orwaitinglistdaoimpl();         waitingevents = orwaitinglistdao.getorwaitinglistkeysbyresource(rkey);         int = 0;         iterator<orwaitinglist> it2 = waitingevents.iterator();         while (it2.hasnext())          {             orwaitinglist = it2.next();             long wplanneddate = orwaitinglist.getwplanneddate().gettime();             if (wplanneddate != 0) {                 date wplanneddateconverted = new date(wplanneddate);                 dtebeginorwaitingitem = convertdate(0, 0, wplanneddateconverted);                 dteendorwaitingitem = convertdate(orwaitinglist.getwduration().intvalue(), orwaitinglist.getwadditionaltime().intvalue(), wplanneddateconverted);             }             reason = orwaitinglist.getwdescription();             defaultscheduleevent newresourceevent = new defaultscheduleevent(reason, dtebeginorwaitingitem, dteendorwaitingitem, orwaitinglist);             newresourceevent.setstyleclass("waitingitem");             eventresourceavailperday.addevent(newresourceevent);         }      }     catch(java.util.emptystackexception ex)     {         system.out.println(ex.getmessage());     }   public static date convertdate(integer wduration, integer wadditionaltime, date availdate) {     calendar cal = calendar.getinstance();     integer wadditionaltimehours, wadditionaltimeminutes;     integer wdurationhours, wdurationminutes;      if(wadditionaltime != 0 || wduration != 0) {         if (wadditionaltime !=0) {             wadditionaltimehours = (int) math.floor (wadditionaltime / 60);             wadditionaltimeminutes = wadditionaltime - (wadditionaltimehours * 60);             cal.settime(availdate);             cal.set(cal.get(calendar.year), cal.get(calendar.month), cal.get(calendar.date), cal.get(calendar.hour_of_day), cal.get(calendar.minute), cal.get(calendar.second));             cal.add(calendar.minute, wadditionaltimeminutes);             cal.add(calendar.hour_of_day, wadditionaltimehours);         }         if (wduration != 0) {             wdurationhours = (int) math.floor (wadditionaltime / 60);             wdurationminutes = wadditionaltime - (wdurationhours * 60);             cal.settime(availdate);             cal.set(cal.get(calendar.year), cal.get(calendar.month), cal.get(calendar.date), cal.get(calendar.hour_of_day), cal.get(calendar.minute), cal.get(calendar.second));             cal.add(calendar.minute, wdurationminutes);             cal.add(calendar.hour_of_day, wdurationhours);         }     } else {         cal.settime(availdate);         cal.set(cal.get(calendar.year), cal.get(calendar.month), cal.get(calendar.date), cal.get(calendar.hour_of_day), cal.get(calendar.minute), cal.get(calendar.second));     }     return cal.gettime(); } 

model update:

<property name="wplanneddate" type="timestamp">   <column length="7" name="w_planned_date">     <comment>planned date</comment>   </column> </property> 

edit: if using .xml hibernate change type timestamp instead of date. <property name="yourdate" column="your_date" type="timestamp" /> therefore have time on database , can use simpledateformat

simpledateformat dateformat = new simpledateformat("dd/mm/yyyy-hh:mm"); dateformat.format(orwaitinglist.getwplanneddate()); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -