6 Replies Latest reply on Oct 21, 2015 8:57 AM by Trevorׅ

    Convert System Time to IST

    BEGINNER_X Level 3

      Hi All,

       

      Is it possible to convert System timing to IST timing?

       

      so far,

       

      nf = new Date();
      nfD = nf.getDate();    nfM = nf.getMonth();    nfY = nf.getFullYear();    nfH = nf.getHours();    nfMi = nf.getMinutes();    nfSec = nf.getSeconds();
      
      var currentTime = nfH+" : " + nfMi+" : " + nfSec;
      alert("currentTime: " + currentTime)
      

       

      Output Screenshot:

       

      Screen Shot 2015-10-19 at 06.33.14.png

       

      Thanks in Advance

      Siraj

        • 1. Re: Convert System Time to IST
          Vamitul Level 4

          If you know the current offset between your system time and IST, simply add or substract it from the nfH.

          Or use Date to get the UTC time, and convert that to IST

          • 2. Re: Convert System Time to IST
            Ronald63 Level 4

            Hi Siraj,

             

            Try this ...

            //date system
            var sysDate = new Date();
            //UTC date
            var utcDate = new Date(sysDate.getTime() + sysDate.getTimezoneOffset() * 60000);
            //India Standard Time (IST) is 5:30 hours ahead of Coordinated Universal Time (UTC)
            var istDate = new Date(utcDate.getTime() + ((5.5*60)) * 60000);
            
            alert('\n System : ' + systemDate + '\n UTC : ' + utcDate + '\n IST : ' + istDate)
            
            

             

            Regards

            • 3. Re: Convert System Time to IST
              BEGINNER_X Level 3

              Thanks for your reply Ronald & Vamitul.....

               

              Ronald: Great stuff you have and very very thankful to yours......

               

              You help me very often. Thanks for your wonderful support.

               

               

              Note: Could you please help me to understand the code.

              1. what is 60000.

              2. If possible, please explain the code

              • 4. Re: Convert System Time to IST
                Ronald63 Level 4

                Hi,

                 

                1. what is 60000 ?


                When you add minutes in a date object, the unit used is milliseconds.


                2. If possible, please explain the code


                // create date system  
                var sysDate = new Date();  
                // create UTC date  
                /* 
                    getTimezoneOffset() returns the difference in minutes between the computer's local time and UTC.
                */
                var utcDate = new Date(sysDate.getTime() + sysDate.getTimezoneOffset() * 60000); 
                
                // create IST date
                /*
                   Indian Standard Time (IST) is the time observed throughout India and Sri Lanka, with a time offset of UTC+05:30.
                */
                var istDate = new Date(utcDate.getTime() + ((5.5*60)) * 60000);  
                  
                alert('\n System : ' + systemDate + '\n UTC : ' + utcDate + '\n IST : ' + istDat
                
                • 5. Re: Convert System Time to IST
                  BEGINNER_X Level 3

                  Heartily Thanks a lot Ronald...

                   

                  Thank you for spending your valuable time for us...

                  • 6. Re: Convert System Time to IST
                    Trevorׅ Adobe Community Professional

                    I deleted the post I had just posted because it didn't work with the .5 hours

                    This would work but is less fun.

                     

                    var now =  new Date();

                    var istDate = new Date (now.setHours(now.getUTCHours() + 5));

                    istDate.setMinutes(now.getUTCMinutes() + 30);

                    alert(istDate);