Created
December 1, 2014 17:38
-
-
Save bbrown/fe3a17fa63a78b5e8b36 to your computer and use it in GitHub Desktop.
Formatting function for dates in JS (for those times when Moment.js isn't feasible)
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
function yyyymmddhhmm(date) | |
{ | |
// Modified from http://stackoverflow.com/a/3067896/20595 | |
var yyyy = date.getFullYear().toString(); | |
var mm = (date.getMonth()+1).toString(); // getMonth() is zero-based | |
var dd = date.getDate().toString(); | |
var hh = date.getHours().toString(); | |
var min = date.getMinutes().toString(); | |
return yyyy + (mm[1]?mm:"0"+mm[0]) + (dd[1]?dd:"0"+dd[0]) + (hh[1]?hh:"0"+hh[0]) + (min[1]?min:"0"+min[0]); // padding | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment