0

I am using a CMS that generates some code for me. I am having the CMS auto-generate the date a page was last updated. (Note: This page contains information that is time sensitive and it is beneficial for the end user to see when the page was last updated.)

The system generates the following time stamp: 24-May-2013 11:54 AM, however, I would prefer the date to look like so: May 24, 2013 (to follow the US Standard way of writing time) and drop the time completely.

The code looks like so:

<p>Last Updated: <span class="time">24-May-2013 11:54 AM</span></p>

I believe this would be possible using jQuery but I do not know how to do this. Any recommendations on how to use jQuery to do this would be welcome!

L84
  • 45,514
  • 58
  • 177
  • 257

2 Answers2

2
$(".time").each(function() {
    var $this = $(this),
        // regex to retrieve day, month and year
        stamp = /([0-9]{1,2})-([a-z]*)-([0-9]{4})/i.exec($this.text())

    $this.html(stamp[2] + " " + stamp[1] + ", " + stamp[3]);
});

See the jsfiddle for demo: http://jsfiddle.net/mifeng/gquhp/

Mifeng
  • 1,525
  • 15
  • 26
0

If you have jQuery UI, you can use datepicker.

$(".time").val($.datepicker.formatDate('M dd yy', new Date())); 
Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83