5 Replies Latest reply: Aug 10, 2008 10:23 PM by 843785 RSS

    Related to date conversion

    843785
      please help me out to convert the date format to mm/dd/yyyy hh:mm PM
      but i am unable to get the value .My code is below

      when i am printing the value of
      out.println("Date=="+ rmInfo.getPropertyStringValue(Property.DATE_CREATED) );
      on console it is showing in this format >> Wed Jul 16 18:31:04 GMT+05:30 2008
      and i want the date to be displayed in this >>> mm/dd/yyyy hh:mm PM - format please Help

      Code which i am trying to execute
      DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
      String s = rmInfo.getPropertyStringValue(Property.DATE_CREATED);
      Date dd = sdf.parse(s);
      sdf = new SimpleDateFormat("dd/MM/yyyy");
      out.println("Mydaate is==="+sdf.format(dd));   
        • 1. Re: Related to date conversion
          843785
          Might be self evident, but as quite new to java i cannot figure out, what type of class is your rmInfo?? if i knew it would be easier to help.
          • 2. Re: Related to date conversion
            843785
            rmInfo is the object ..In that object i am calling method on it
            try {
                        response.setContentType("text/html");
                        PrintWriter out = response.getWriter();
                        RMObjectStore loRMOS = null;
                        ObjectStore fileplan_os= null;
                        ServletContext application = getServletContext();
                        WcmDataStore ds = WcmDataStore.get(application, request, true);
                        String lstrFilePlanObjectStoreName   = (String)ds.getValue("currentObjectStoreName");
                        fileplan_os = ObjectFactory.getObjectStore(lstrFilePlanObjectStoreName, ds.getServerCredentials().getSession());
                        loRMOS = RMUtil._getRMObjectStore(fileplan_os);
                        RMObject loRMObject = loRMOS.getObject(request.getParameter("id"));
                        RecordInfo rmInfo = (RecordInfo)loRMObject;
                        String rmInfoProps[] = {"UNFCCC_Filename",
                                                      "UNFCCC_Addressee",
                                                      "UNFCCC_Creator",
                                                      "UNFCCC_Country",
                                                      "UNFCCC_Date_Acquired",
                                                      "UNFCCC_Date_Created",
                                                      "UNFCCC_Organization",
                                                      "UNFCCC_Format",
                                                      "UNFCCC_Language","UNFCCC_MIMEType","UNFCCC_Size","UNFCCC_Subject"}; 
                        String rmInfoNames[] = {"File Name",
                                  "Addressee",
                                  "Creator",
                                  "Country",
                                  "Date Acquired",
                                  "Date Created",
                                  "Organization",
                                  "Format",
                                  "Language","MIMEType","Size","Subject"};
                        sBaseURL = WcmUi.getBasePath(request);
                        Properties props = rmInfo.getProperties(rmInfoProps);
                        String classId = rmInfo.getClassId();
                        ClassDescription classDesc =(ClassDescription)fileplan_os.getObject(BaseObject.TYPE_CLASSDESCRIPTION,classId);
                        PropertyDescriptions propsDes = classDesc.getPropertyDescriptions(false);
                        //Display all the system properties 
                        //  propsDes = (PropertyDescriptions)propsDes.filterByProperty(Property.DESCRIPTIVE_TEXT, 
                        //PropertyDescriptions.IS_GREATER_OR_EQUAL, "declare,UNFCCC");
                        propsDes = (PropertyDescriptions)propsDes.filterByProperty(Property.DESCRIPTIVE_TEXT,
                        PropertyDescriptions.IS_EQUAL, "declare,UNFCCC");
                        
                        out.println("Date11111111=="+rmInfo.getPropertyStringValue(Property.DATE_CREATED));
                            
                         DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                        String s = rmInfo.getPropertyStringValue(Property.DATE_CREATED);
                         Date dd = sdf.parse(s);
                        sdf = new SimpleDateFormat("dd/MM/yyyy");
                        out.println("Mydaate is==="+sdf.format(dd));
                        Property prop=null;
                        out.println("<html><head>");
                             out.println(" <link rel='stylesheet' href='" + sBaseURL + "/css/Wcm.css' type='text/css'>");
                             out.println(" <link rel='stylesheet' href=>");
                                  out.println("<body>");
                                  out.println("<table>");     
                                  out.println("<tr class='wcmPathText'>");
                                  //basit
                                  //to match the MIMEtype and display the image in the UI. 
                                   if(rmInfo.getPropertyStringValue("UNFCCC_MIMEType").equals("application/msword"))
                                    {out.println("<td class='wcmPathText'><span class='wcmPathLabel' width='12'height='20' >Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Doc16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                  else if(rmInfo.getPropertyStringValue("UNFCCC_MIMEType") .equals("application/pdf"))
                                  {out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Pdf16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                  else if(rmInfo.getPropertyStringValue("UNFCCC_MIMEType") .equals("application/vnd.ms-excel"))
                                  {out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Xls16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                  else if(rmInfo.getPropertyStringValue("UNFCCC_MIMEType") .equals("application/vnd.ms-powerpoint"))
                                  {out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Ppt16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                  else if(rmInfo.getPropertyStringValue("UNFCCC_MIMEType") .equals("image/jpeg"))
                                  {out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Jpg16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                  else if(rmInfo.getPropertyStringValue("UNFCCC_MIMEType") .equals("text/plain"))
                                  {out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Txt16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                  else if(rmInfo.getPropertyStringValue("UNFCCC_MIMEType") .equals("image/bmp"))
                                  {out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Bmp16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                  else
                                  {out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'>   <img title='Electronic Record' src='images/type/ExternalDocument16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");}
                                   //word::out.println("<td class='wcmPathText'><span class='wcmPathLabel' width='12'height='20' >Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Doc16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");
                                   // ppt::out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Pdf16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");
                                   // execl::out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Xls16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");
                                    //ppt::out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Ppt16.gif' border='0' height='16' width='16' align='texttop'></a><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");
                                   //TExt::out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Txt16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");
                                    //BMP::out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'><img title='Electronic Record' src='images/mime/Bmp16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");
                                    //TExtTOP::out.println("<td class='wcmPathText'><span class='wcmPathLabel'>Record: </span></td><td class='wcmPathText'>   <img title='Electronic Record' src='images/type/ExternalDocument16.gif' border='0' height='16' width='16' align='texttop'><img src='images/state/None16.gif' title='' width='6' height='16'>"+loRMObject.getName()+"</td>");
                                  out.println("</tr>");
                                  out.println("</table>");
                                       out.println("<table>");
                                            out.println("<tr>");
                                               out.println("<th width='1%' class='wcmFormMainHeader'><img height='20' width='20' src='images/web/common/Spacer.gif' alt=''></th><th class='wcmFormMainHeader' align='left'>Property</th><th class='wcmFormMainHeader' align='left'>Value</th>");
                                                    out.println("</tr>");
                                                    
                                                    for (Iterator iter1 = propsDes.iterator(); iter1.hasNext();)
                                                        for (int i = 0; i < rmInfoProps.length ; i++)
                                                                     {
                                                             
                                                                    prop =(Property)props.get(i);
                                                                    PropertyDescription loProp       = (PropertyDescription)iter1.next();
                                                                     boolean value = loProp.getPropertyBooleanValue(Property.IS_VALUE_REQUIRED);
                                                                    // SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/YY HH:MM");
                                                                    // String myDate = sdf.format(loProp.getPropertyDateValue(Property.DATE_CREATED));
                                                                     //String myDate =  sdf.format(prop.getValue());
                                                                     // declare date variable and manipulate !
                                                                     // continue
                                                                    // out.println("MyDateis::"+myDate);
                                                                     //out.println("Date==="+loProp.getPropertyStringValue(prop.DATE_CREATED));
                                                                    
                                                              if(i%2==0){
                                                                     if (value == false && prop.hasNullValue()==false && prop.getType()!=0 ){
                                                                        out.println("<tr>");
                                                                        out.println("<td height='20' width='20' class='wcmFormRowOdd'><img height='15' width='15' src='images/state/Required16.gif' border='0' title='Required'></td><td nowrap='true' width='170' scope='row' class='wcmFormRowOdd'>"+prop.getLabel().replaceAll(prop.getName(), rmInfoNames)+"</td><td class='wcmFormRowOdd'>"+prop.getValue().toString().trim()+"</td>");
                                                                        out.println("</tr>");
                                                                        }//if
                                                                   else{
                                                                        if (value == true || prop.hasNullValue()==true && prop.getType()==0)
                                                                        out.println("<tr>");
                                                                        out.println("<td height='20' width='20' class='wcmFormRowOdd'><td nowrap='true' width='170' scope='row' class='wcmFormRowOdd'>"+prop.getLabel().replaceAll(prop.getName(), rmInfoNames[i])+"</td><td class='wcmFormRowOdd'></td>");
                                                                        out.println("</tr>");
                                                                        
                                                                        }
                                                              }
                                                              else{
                                                                        // VALUE OF i is odd
                                                                             
                                                                   if ( value == false && prop.hasNullValue()==false && prop.getType()!=0 )
                                                                   {
                                                                        
                                                                        if (i== 4)
                                                                        {
                                                                             //SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/YY HH:MM");
                                                                             //String myDate = sdf.format(prop.getValue());
                                                                             // declare date variable and manipulate !
                                                                             // continue
                                                                             //out.println("MyDateis::"+myDate);
                                                                             
                                                                        }
                                                                             out.println("<tr>");
                                                                             out.println("<td height='20' width='20' class='wcmFormRowEven'><img height='15' width='15' src='images/state/Required16.gif' border='0' title='Required'></td><td nowrap='true' width='170' scope='row' class='wcmFormRowEven'>"+prop.getLabel().replaceAll(prop.getName(), rmInfoNames[i])+"</td><td class='wcmFormRowEven'>"+prop.getValue().toString().trim()+"</td>");
                                                                             out.println("</tr>");
                                                                             }//if
                                                                        else{
                                                                             if (value == true || prop.hasNullValue()==true && prop.getType()==0)
                                                                             out.println("<tr>");
                                                                             out.println("<td height='20' width='20' class='wcmFormRowEven'><td nowrap='true' width='170' scope='row' class='wcmFormRowEven'>"+prop.getLabel().replaceAll(prop.getName(), rmInfoNames[i])+"</td><td class='wcmFormRowEven'></td>");
                                                                             out.println("</tr>");
                                                                             }
                                                                   }
                                                    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
            • 3. Re: Related to date conversion
              843785
              Can't you do that with a Calendar object, using the get(int field) method?
              • 4. Re: Related to date conversion
                796365
                To parse a date that is a string, you must create a format that matches the string being parsed.
                And this doesn't:
                DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                The same thing goes for output - your "dd/MM/yyyy" output format string won't print the data with the format you want.
                • 5. Re: Related to date conversion
                  843785
                  Thanks a lot , for your answer , It workes perfectly ,