Nate Woods

Nate Woods

JavaScript format date

2013-01-01

Humminbird and their helpers.js file, where they add a simple time formatting function to their Date object.

Date.prototype.formattedTime = function() {
  var formattedDate = this.getHours();

  var minutes = this.getMinutes();
  if(minutes > 9) {
    formattedDate += ":" + minutes;
  } else {
    formattedDate += ":0" + minutes;
  }

  var seconds = this.getSeconds();
  if(seconds > 9) {
    formattedDate += ":" + seconds;
  } else {
    formattedDate += ":0" + seconds;
  }

  return formattedDate;
};

Now this is nice for simply formatting time, but I was looking for something a little more elegant; closer to PhP’s date formatting. I’ve looked around a few places and jQuery UI has a nice option along with this guy’s nice encapsulated design, but I’m looking for something sleeker and a little slimmer. Currently I am Fiddling to find a better solution…

Open tabs at last development

×