make formatdates function shared in utils

This commit is contained in:
2023-10-24 07:35:43 +01:00
parent 0c98bcd831
commit 798ba01ea6
6 changed files with 481 additions and 110 deletions
+18
View File
@@ -417,3 +417,21 @@ export const bytesToSize = (bytes) => {
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i];
};
export const formatDates = (dateObj, showTime) => {
var dateObj = new Date(dateObj);
var dd = String(dateObj.getDate()).padStart(2, "0");
var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0!
var yyyy = dateObj.getFullYear();
var hh = dateObj.getHours();
hh = ("0" + hh).slice(-2);
var mins = dateObj.getMinutes();
mins = ("0" + mins).slice(-2);
const dateStr = showTime
? hh == 0 && mins == 0
? ""
: hh + ":" + mins
: dd + "/" + mm + "/" + yyyy + " ";
return dateStr;
};