Skip to content

Instantly share code, notes, and snippets.

@Merazsohel
Created December 15, 2021 09:31
Show Gist options
  • Save Merazsohel/4251f28e77dd23a085f32698a1c12239 to your computer and use it in GitHub Desktop.
Save Merazsohel/4251f28e77dd23a085f32698a1c12239 to your computer and use it in GitHub Desktop.
function pad2(n)
{
return (n < 10 ? '0' : '') + n;
}
var date = new Date(date goes here);
var month = pad2(date.getMonth()+1);
var day = pad2(date.getDate());
var year= date.getFullYear();
var formattedDate = day+"-"+month+"-"+year;
alert (formattedDate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment