Format Time of Day as a String

The following sample formats the time of day as a string using format.format(options).

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /**
 * @NApiVersion 2.x
 */

require(['N/format'], 
    function(format){
         function formatTimeOfDay() {
              // Instantiate a new Date object assuming it's now 7:01PM. 
              const now = new Date();
              // Select a format from the format.Type enum. In this case TIMEOFDAY
              return format.format({value: now, type: format.Type.TIMEOFDAY})  
              }
         const formattedTime = formatTimeOfDay(); // "7:01 pm" -- a string 
  }); 

        

General Notices