Converting Time to NetSuite format while working in suitelet script type

function netSuiteTimeFormat(time) {

            if (!time) return ;

            let dateObj = new Date(time);

            let hours = dateObj.getHours();

            let minutes = dateObj.getMinutes();

            let period = ‘AM’;

            if (hours >= 12) {

              period = ‘PM’;

              if (hours > 12) {

                hours -= 12;

              }

            }

            if (hours === 0) {

              hours = 12;

            }

            return `${hours}:${minutes < 10 ? ‘0’ + minutes : minutes} ${period}`;

          }

Leave a comment

Your email address will not be published. Required fields are marked *