2 Replies Latest reply on Jan 21, 2015 12:30 AM by Teetan VK

    How to change Date Time toString?

    Teetan VK Level 1

      Hi everyone

       

      I got this script

       

      var docs = app.documents; 

      for (var i = docs.length-1; i >= 0; i--) { 

          if (docs[i].saved == false) { 

              docs[i].save(new File("~/Desktop/Doc" + (i+1) "-" + new Date().toLocaleTimeString() + ".indd")); 

              docs[i].close(); 

          } 

          else { 

              docs[i].close(SaveOptions.YES); 

          } 

      }

       

      Can someone tell me how can change the date, time string

       

      into like this:

       

      day, month, year. hour, minute

       

      Doc1-21 January 2015 13:11

       

      Thanks

      Regard

       

      Teetan

        • 1. Re: How to change Date Time toString?
          Sajeev Sridharan Level 4

          Try this,

           

          var myDate = new Date;
          Date.prototype.monthName = function() {
              var myMonth = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
              return myMonth[this.getMonth()];
          }//This line was proposed by Marijan Tompa (tomaxxi)
          
          
          var myMonthName = myDate.monthName();
          var myYear = myDate.getFullYear();
          var myHour = myDate.getHours();
          var myMinutes = myDate.getMinutes();
          
          
          var docs = app.documents; 
          for (var i = docs.length-1; i >= 0; i--) { 
              if (docs[i].saved == false) { 
                  docs[i].save(new File("~/Desktop/Doc" + (i+1) + "-" + myDate.getDate() + " " + myMonthName + " " + myYear + " " + myHour + "-" + myMinutes + ".indd")); //We cannot insert "colon" in the file name, hence I have repalced with hyphen
                  docs[i].close(); 
              } 
              else { 
                  docs[i].close(SaveOptions.YES); 
              } 
          }
          

           

           

          Vandy

          • 2. Re: How to change Date Time toString?
            Teetan VK Level 1

            Thank you Vandy

            Thank you very much

             

            Teetan