Date formatting function for Example ballot
<!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> |
// 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