Repository URL to install this package:
|
Version:
3.12.2 ▾
|
/**
* Returns a date in the all formats
*/
export default function getDateString(format, spaceType, timeStamp) {
var dateObject = timeStamp ? new Date(timeStamp) : new Date();
var getMonth = dateObject.getMonth() + 1;
var getDay = dateObject.getDate();
var month = getMonth < 10 ? '0' + getMonth : getMonth;
var day = getDay < 10 ? '0' + getDay : getDay;
var year = dateObject.getFullYear();
switch (format) {
case 'mdy':
return month + spaceType + day + spaceType + year;
case 'dmy':
return day + spaceType + month + spaceType + year;
case 'ymd':
return year + spaceType + month + spaceType + day;
}
}