rick beron13 reputationPosted Oct 18, 2020, 7:56 PM EDT
+2
The JSON specification does not specify a format for exchanging dates which is why there are so many different ways to do it. The problem with dates in JSON and JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript/jQuery following Date constructor straight away converts the milliseconds since 1970 to Date as follows:
var jsonDate = new Date(1297246301973);
Then let's convert it to js format:
var date = new Date(parseInt(jsonDate.substr(6)));
The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .
For ISO-8601 formatted JSON dates, just pass the string into the Date constructor:
var date = new Date(jsonDate);
http://net-informations.com/jq/iq/jdate.htm
+2
Ankit KanojiaRank #380 · 6.6K reputationPosted Jan 4, 2021, 3:51 AM EST
+2
Hi Reylin Mathew,
Please try below single line code, it will work for you as per your requested format for date.
new Date("8/9/2019").toLocaleDateString('en-US', {year: 'numeric', month: '2-digit', day: '2-digit'});
This will return the date value with format like "08/09/2019"
+2
Vishal PatelRank #3,290 · 437 reputationPosted Aug 9, 2019, 3:54 AM EDT
+1
You can check below link to use moment js is best for any type of date conversion
please follow this url and generate output based on your requirment.
http://jsfiddle.net/JamesWClark/9PAFg/
+1
Bidyasagar MishraRank #766 · 3K reputationPosted Aug 9, 2019, 4:36 AM EDT
Amit MohantyRank #112 · 20K reputationPosted Aug 9, 2019, 3:07 AM EDT
Ravishankar NRank #241 · 10.2K reputationPosted Sep 17, 2019, 7:36 PM EDT
Yogeshkumar HadiyaRank #358 · 7K reputationPosted Jan 4, 2021, 11:57 AM EST
Priyanka JainRank #356 · 7K reputationPosted Aug 9, 2019, 3:41 AM EDT
Ajay GohilRank #2,370 · 599 reputationPosted Dec 10, 2020, 5:03 PM EST
rick beron13 reputationPosted Oct 18, 2020, 7:56 PM EDT
Ankit KanojiaRank #380 · 6.6K reputationPosted Jan 4, 2021, 3:51 AM EST
Vishal PatelRank #3,290 · 437 reputationPosted Aug 9, 2019, 3:54 AM EDT
Bidyasagar MishraRank #766 · 3K reputationPosted Aug 9, 2019, 4:36 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts