Last active
December 31, 2015 00:39
-
-
Save benhodgson87/7909341 to your computer and use it in GitHub Desktop.
Date formatting function for Example ballot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="date"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Date formatting function | |
function dateFormat(input) { | |
// Turn our input date into a JS Date | |
var dateIn = new Date(input); | |
// Array of Month Names | |
var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" ]; | |
// Create return object | |
var dateOut = {}; | |
// Fill object | |
dateOut.day = dateIn.getDate(); | |
dateOut.month = monthNames[dateIn.getMonth()]; | |
dateOut.year = dateIn.getFullYear(); | |
// Return the object | |
return dateOut; | |
} | |
// Create a variable of our formatted date object | |
var eventDate = dateFormat('2014-03-13'); | |
// Push it into the DOM | |
$('#date').append(eventDate.day + ' ' + eventDate.month); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment