Skip to content

Instantly share code, notes, and snippets.

@raco
Created November 14, 2019 20:21
Show Gist options
  • Save raco/88765110a63490e7f74c95c404d6c444 to your computer and use it in GitHub Desktop.
Save raco/88765110a63490e7f74c95c404d6c444 to your computer and use it in GitHub Desktop.
Format date dd mm yyyy for dummies
formatDate(_date: Date, separator = '/') {
const day = _date.getDate();
const month = _date.getMonth() + 1;
const year = _date.getFullYear();
if (month < 10) {
return `${day}${separator}0${month}${separator}${year}`;
} else {
return `${day}${separator}${month}${separator}${year}`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment