0

What kind of code should I use so that jQuery looks for every YYYY-MM-DD formatted (plain text) string on a page and it replaces it with DD-MM-YYYY?

Thanks a lot!

1
  • I'd strongly suggest encompassing the dates with a recognisable element, rather than trusting (any) JavaScript to reliably parse and convert plain-text strings meaningfully. Commented Nov 15, 2010 at 19:11

1 Answer 1

1

That might work:

$(document.body).contents().each(function(i,e) {
    $(e).text(function(i,text) {
        return text.replace(/(\d+)-(\d+)-(\d+)/g, function($full, $year, $month, $day) {
            return [$day, $month, $year].join('-');
        });
    });
});

Example: http://www.jsfiddle.net/Jm2UQ/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.