Skip to content

Instantly share code, notes, and snippets.

@benhodgson87
Last active December 31, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhodgson87/7909341 to your computer and use it in GitHub Desktop.
Save benhodgson87/7909341 to your computer and use it in GitHub Desktop.
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