Author Topic: Time conversion from milliseconds  (Read 3666 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 95
    • View Profile
Time conversion from milliseconds
« on: July 25, 2016, 03:45:02 PM »
Purpose:
Convert milliseconds to Days/Hours/Minutes/Seconds depending on milliseconds value.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// 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;
}

// User Interface
clearscreen();
inputfield([1,0], "Enter time in milliseconds", [1,28], {"size":10, "name":"z_milliseconds"});
inputfield([2,0], "Milliseconds converted to ", [2,28], {"size":10, "name":"z_converted_ms", "readonly":true});
pushbutton([3,7],"@01@Convert milliseconds", "?", {"process":convertMilliseconds});


See attachments for code samples!
« Last Edit: July 25, 2016, 03:47:36 PM by Benjamin Dasari »