Fantastic Little Javascript Date Formatter

SquirrelFish.jpg

This morning I needed to have a nice, simple, quick, date formatter for my Javascript code. Nothing fancy, but since Javascript really only allows you to manipulate the components of the date, and not really format it nicely, something else is needed. So I went 'a Googling. Found something that's really quite nice.

The idea is that with a simple:

  <script type="text/javascript" src="data.format.js"/>

you can then include in your java script code:

  var label = document.getElementById("label")
 
  label.innerHTML = dateFormat(new Date(), "HH:MM:ss mmmmm dd, yyyy");

where you had tagged the date/time field like this:

  <div id="label">this will be the time</div>

What I get in my code is the updated time and date of the last update to the data. It's pretty nice. A little CSS on the div tag and it's looking pretty nice. I have to say, I'm a little surprised that Javascript didn't have this, but to see it in the open source community makes me feel very good about Javascript. It's there, and it's really being supported by the developers.

So... if you need a Javascript date formatter, give this guy a look.