<%@ page import="java.text.*;"%>
        <%!
            String billdate="";
            SimpleDateFormat sdfSource,sdfDestination;
                    //there is sql Date is also availbe so u have to write following way
            java.util.Date date;
                    //this method convert user date to database formate
            public String UITODB(String bdate)
            {
                try
                {
                     sdfSource = new SimpleDateFormat("dd/MM/yyyy");
                     date = sdfSource.parse(bdate);
                     sdfDestination = new SimpleDateFormat("yyyy-MM-dd");
                     billdate=sdfDestination.format(date);
                     
                }
                catch(Exception e)
                {
                    
                }
                return billdate;
                
            }
            
            //this method convert databse mysql formate to user date
            public String DBTOUI(String bdate)
            {
                try
                {
                     sdfSource = new SimpleDateFormat("yyyy-MM-dd");
                     date = sdfSource.parse(bdate);
                     sdfDestination = new SimpleDateFormat("dd/MM/yyyy");
                     billdate=sdfDestination.format(date);
                     
                }
                catch(Exception e)
                {
                    
                }
                return billdate;
                
            }
                       
           
        %>
        //how to call above function
        
    <%=UITODB("04/02/1987")%> //this will print:1987-02-04
    
    <%=DBTOUI("1987-02-04")%>  //this will print:04/02/1987
 
No comments:
Post a Comment