salix/loopback/util/date.js

26 lines
480 B
JavaScript

/**
* Transforms a UTC date to string without datetime.
*
* @param {date} date Date to format
* @return {String} Formatted date string
*/
function toString(date) {
date = new Date(date);
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
if (day < 10)
day = `0${day}`;
if (month < 10)
month = `0${month}`;
return `${day}-${month}-${year}`;
}
module.exports = {
toString: toString
};