Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Date formatting function for Example ballot
<!DOCTYPE html>
<script src=""></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<div id="date"></div>
// 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 = 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.month);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment