salix/front/core/lib/date.js

22 lines
456 B
JavaScript
Raw Normal View History

2018-05-24 09:21:44 +00:00
/**
* Transforms a UTC date to JSON date without datetime.
*
2018-05-24 09:21:44 +00:00
* @param {date} date Date to format
* @return {String} Formatted date string
*/
export function toJsonDate(date) {
date = new Date(date);
2018-05-24 09:21:44 +00:00
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
if (day < 10)
day = `0${day}`;
2018-05-24 09:21:44 +00:00
if (month < 10)
month = `0${month}`;
2018-05-24 09:21:44 +00:00
return new Date(`${year}-${month}-${day}`);
}