Advertisement
Cristian-Paolini

Format Date / Time OData Service SAPUI5

May 24th, 2023
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.25 KB | Source Code | 0 0
  1. formatTime: function(aDownloads) {
  2.   aDownloads.forEach(download => {
  3.     download.UnloadBeginTim = formatter.formatTime(download.UnloadBeginTim.ms);
  4.     download.UnloadEndTim = formatter.formatTime(download.UnloadEndTim.ms);
  5.  
  6.     const formatDateTime = (date, time) => {
  7.       const dateTimeDesc = new Date(
  8.         date.getUTCFullYear(),
  9.         date.getUTCMonth(),
  10.         date.getUTCDate(),
  11.         parseInt(time.split(':')[0]),
  12.         parseInt(time.split(':')[1]),
  13.         parseInt(time.split(':')[2])
  14.       );
  15.  
  16.       const day = dateTimeDesc.getDate();
  17.       const month = dateTimeDesc.getMonth() + 1;
  18.       const year = dateTimeDesc.getFullYear();
  19.       const hours = dateTimeDesc.getHours();
  20.       const minutes = dateTimeDesc.getMinutes();
  21.       const seconds = dateTimeDesc.getSeconds();
  22.  
  23.       return `${day.toString().padStart(2, "0")}-${month.toString().padStart(2, "0")}-${year.toString()} - ${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
  24.     };
  25.  
  26.     download.UnloadBeginDat = formatDateTime(download.UnloadBeginDat, download.UnloadBeginTim);
  27.     download.UnloadEndDat = formatDateTime(download.UnloadEndDat, download.UnloadEndTim);
  28.   });
  29.  
  30.   return aDownloads;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement