jsp - java String to Date conversion and re-convert date format dd/mm/yy to dd/mm/yyyy -
in application i've set default value in input text box(a jsp file) date.i m fetching oracle database fetches string.so i've convert date.the problem in conversion. picks date '30-apr-2013' .i've convert in date re-convert desire date format 'dd/mm/yyyy'. in webservice write following:
@webmethod(operationname = "currenteod") public string currenteod() { string result = null; try{ string sql="select to_char(to_date(max(dat_eod),'dd-mon-yyyy'),'dd/mm/yyyy')"; transactionmanager tm=transactionmanager.getinstance(); try { tm.begin(); result=tm.executescalar(sql).tostring(); system.out.println(result); tm.end(); system.out.println("transaction end..... " ); } catch(exception e) { tm.rollback(); system.out.println("service: " + e); } } catch(exception ex) { system.out.println("exception: " + ex); } return result; }
now when invoke in jsp page this:
java.lang.string result = port.currenteod(); out.println(result); } catch (exception ex) { } %> <%-- end web service invocation --%>" size="20px" style="color: #aaaaaa"/> <img style="cursor: hand" src="calendar/images/calendar.jpg" onclick="displaycalendar(document.forms[0].txtfromdate,'dd/mm/yyyy',this)" alt="calendar"/>
///my code
here result=30/04/0013 in oracle database dat_eod= 30-apr-13
after using to_char , to_date returns 30/04/0013
how convert 30/04/2013
please consider store in database type timestamp. converted java date , not need conversions. (also, supported hibernate if want use in future)
Comments
Post a Comment