Liquid UI - Documentation - 9.03 Convert time from milliseconds to days/hours/minutes/seconds.

9.03 Convert time from milliseconds to days/hours/minutes/seconds.


Prerequisites


Purpose

Learn how to convert milliseconds into days/hours/minutes/seconds. We will walk you through the following steps.

  1. Delete an Activex container
  2. Add two input fields
  3. Add a pushbutton
  4. Add functionality to convert milliseconds

//Create this file inside your script folder for customizing the SAP Easy Access screen: SAPLSMTR_NAVIGATION.E0100.sjs
//Now let's start adding the content to the above file

  1. Delete an Activex container on the SAP Easy Access screen.
    //Deletes an image container
    del('X[IMAGE_CONTAINER]');
    
     

     
  2. Add two inputfields namely, Enter time in milliseconds and Milliseconds converted to.
    //Creates an input field to enter the time in milliseconds 
    inputfield([1,0], "Enter time in milliseconds", [1,28], {"size":10, "name":"z_milliseconds"});
    //Creates an input field which is non editable and assigns time after converting milliseconds into seconds or minutes or hours or days in the inputfield.
    inputfield([2,0], "Milliseconds converted to ", [2,28], {"size":10, "name":"z_converted_ms", "readonly":true});
    
     

     
  3. Add a pushbutton as Convert milliseconds.
    //Creates a pushbutton to execute a process convertMilliseconds on click.
    pushbutton([3,7],"@01@Convert milliseconds", "?", {"process":convertMilliseconds});
    
     

     
  4. Add functionality to convert the millisecond's value into the seconds or minutes or hours or days based on the value entered in the inputfield.
    Enter the time in milliseconds and click ConvertMilliseconds.
    // Function to convert milliseconds to Days/Hours/Minutes/Seconds depending on milliseconds value
    function timeConversion(millisec) {
    var seconds = (millisec / 1000).toFixed(2);
    var minutes = (millisec / (1000 * 60)).toFixed(2);
    var hours = (millisec / (1000 * 60 * 60)).toFixed(2);
    var days = (millisec / (1000 * 60 * 60 * 24)).toFixed(2);

    if (seconds < 60) {
    return seconds + " Sec";
    } else if (minutes < 60) {
    return minutes + " Min";
    } else if (hours < 24) {
    return hours + " Hrs";
    } else {
    return days + " Days"
    }
    }

    function convertMilliseconds(){
    var res = timeConversion(z_milliseconds);
    set('V[z_converted_ms]','&V[res]');
    return;
    }
     

     
  5. You will see the time converted into either seconds or minutes or hours or days based on the millisecond's value.
     

     


Next Steps

Validate Japanese Half-Width(Hankaku) Katakana Character
Learn how to convert time entered in an input field in milliseconds to Days/Hours/Minutes/Seconds.

10 min.

This article is part of the Take a deep dive into the input field and pushbutton tutorial.


Can't find the answers you're looking for?