Skip to content

Instantly share code, notes, and snippets.

@Sadicko
Created June 9, 2019 17:35
Show Gist options
  • Save Sadicko/bafbacd69d3efc57692b5a5fd770db9c to your computer and use it in GitHub Desktop.
Save Sadicko/bafbacd69d3efc57692b5a5fd770db9c to your computer and use it in GitHub Desktop.
How to format a date using jquery
$.date = function(dateObject) {
var d = new Date(dateObject);
var day = d.getDate();
var month = d.getMonth() + 1;
var year = d.getFullYear();
if (day < 10) {
day = "0" + day;
}
if (month < 10) {
month = "0" + month;
}
var date = day + "/" + month + "/" + year;
return date;
};
Output: dd/mm/yyyy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment