Format and display today's date

by andyjh07

HTML

<div id="date"></div>

JavaScript

// Day names, beginning with Sunday
var d_names = new Array("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday");

//Month names, beginning with January
var m_names = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");

//Set some variables to store today's date in
var d = new Date();
//Find out today's day
var curr_day = d.getDay();
//Find out the actual date of today (example - 27)
var curr_date = d.getDate();

//Define what comes after the number (example - 1st, 2nd & 3rd)
var sup = "";
if (curr_date == 1 || curr_date == 21 || curr_date == 31)
   {
   sup = "st";
   }
else if (curr_date == 2 || curr_date == 22)
   {
   sup = "nd";
   }
else if (curr_date == 3 || curr_date == 23)
   {
   sup = "rd";
   }
else
   {
   sup = "th";
   }
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
//Then output the date in a nice format like Monday 1st January 2013 to the div id of date
$('#date').html(d_names[curr_day] + " " + curr_date + "<SUP>"
+ sup + "</SUP> " + m_names[curr_month] + " " + curr_year);