0

I'm having an issue with the date format when getting JSON Date/Time.

I've managed to get the date format to: 2009-06-25T17:32:10.0000000

But I need to be: 25/06/2009 17:32:10

But since I'm getting this data from a loop I've trouble finding out how exactly to format the date so that the data is still extracted correctly in the loop. So far the closest I've come is using the Jquery FormatDateTime (which I've added a script Reference for at the start of the document):

//Get Pages Visited
        response.Result.PagesViewed.forEach(function (o, i, arr) {
            o.PageTime = $formatDateTime('dd/mm/yy hh:ii', o.PageTime);
            $('#PagesViewedRows').html("<tr class='info'><td>" + o.PageTime + "</td><td>" + o.PageStatus + "</td><td>" + o.PageName + "</td></tr>");
});

How can I format the o.PageTime to display correctly?

5
  • you want to store the formatted date for later use? or what? Commented Jun 15, 2015 at 14:24
  • Nah I want to display it inside <td>" + [formatted date here] + "</td> Commented Jun 15, 2015 at 14:26
  • First we need to know o.PageTime format... Commented Jun 15, 2015 at 14:26
  • "I've managed to get the date format to: 2009-06-25T17:32:10.0000000" Commented Jun 15, 2015 at 14:27
  • which plugin is this, exactly? jqueryui? or agschwender's? Commented Jun 15, 2015 at 14:28

2 Answers 2

1

You don't really need JQuery for that. Plain javascript works as well:

var date = new Date('2009-06-25T17:32:10.0000000');
console.log(date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds());
Sign up to request clarification or add additional context in comments.

Comments

0

Try

var d = new Date().toJSON().split(/-|T|\..*/).filter(Boolean);
var res = d.slice(0, 3).reverse().join("/").concat(" " + d.slice(-1));
console.log(res);

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.