Skip to content

Instantly share code, notes, and snippets.

@danielnaranjo
Last active February 5, 2018 13:28
Show Gist options
  • Save danielnaranjo/664715e72bd420afed32b998e5276046 to your computer and use it in GitHub Desktop.
Save danielnaranjo/664715e72bd420afed32b998e5276046 to your computer and use it in GitHub Desktop.
Reformat Simple date.
// As you know how's date is coming
// You do not need to validate or do something else..
// Example: 2018-02-05 12:00 but you date to be displayed need to be: dd/mm/yyyy
// Display into HTML tag like <div id="demo"></div>
// document.getElementById("demo").innerHTML = reformat('2018-02-05 12:00');
var reformat = function(input){
var original = input.split(" "); // Split: This one: 2018-02-05 and this one: 12:00
var changed = original[0].split("-") // Now, split it again to: DD/MM/YYYY
return changed[2]+'/'+changed[1]+'/'+changed[0]; // Returned!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment