1

I have this json result in browser from aggregation I've done:

{
'reportDate': {
    $date: 1424044800000
}
},

I have it stored in mongo db like this: 'reportDate':ISODate("2014-11-17T00:00:00Z") how to convert it in format 'YYYY/mm/dd' using jquery

1 Answer 1

1

In pure JavaScript you can format it like that:

var d = new Date(1424044800000)

var string = (d.getYear() + 1900) + "/" + (d.getMonth() + 1) + "/" + d.getDay();

jQ does not have function that formats date, you would have to use a plugin for that. For example this one

If you are using jquery ui you can use

$.datepicker.formatDate('dd-mm-yy', dateString);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help, this javascript worked great beside dhe day it is showing only 1(first) day for every registred date
Thanks sir, I just used getDate instead of getDay and it retrieved me the right day...

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.