needs understanding of this format of date and time

needs understanding of this format of date and time



I just came across this format of start and end in the codebase which is probably the starting and ending date and time.However, I could not figure out this.
I know how to generate date and time in javascript but I need to generate it in this format to be able to fetch data from API.
Here is the format.


start : '2018-06-20T11:44:21.938Z',
end : '2018-07-20T11:44:21.938Z',



At the same time, I would like to know how to get date and time with exact this format?




6 Answers
6




var date = new Date(Date.parse('2018-06-20T11:44:21.938Z'));



It's ISO 8601 format.
Check this:
https://en.wikipedia.org/wiki/ISO_8601



It is ISO format of the date. You can use toISOString() method to achieve it:


toISOString()




// current date
var date = new Date();
console.log(date);
console.log(date.toISOString());


let date = new Date( Date.parse('2018-06-20T11:44:21.938Z'));



To retrieve date & time separately.


date.toLocaleDateString();
date.toLocaleTimeString()'



To convert any date object to your desired format (ISO Dates):


var date = new Date();
date.toISOString();





Can you tell me how to generate date exact this way?Y es, your answer helped to understand.
– satyajeet jha
Sep 5 '18 at 12:16



Have a look at toISOString() in MDN


toISOString()


var event = new Date('05 October 2011 14:48 UTC');
console.log(event.toString());
// expected output: Wed Oct 05 2011 16:48:00 GMT+0200 (CEST)
// (note: your timezone may vary)

console.log(event.toISOString());
// expected output: 2011-10-05T14:48:00.000Z



That is the ISO date format.



similar to this:



How do I output an ISO 8601 formatted string in JavaScript?



Here is code to produce it.




function myFunction()
var d = new Date();
var n = d.toISOString();
document.getElementById("demo").innerHTML = n;


<button onclick="myFunction()">convert to ISO date format</button>

<p id="demo"></p>



It is an ISO date. Check this link for some info:
https://www.w3schools.com/js/js_date_formats.asp




var istDate = new Date(); // will return: Wed Sep 05 2018 17:50:39 GMT+0530 (India Standard Time)
var isoDate = istDate.toISOString(); // will return in ISO format i.e. "2018-09-05T12:20:39.732Z"
var dateString = istDate.toDateString(); // will return in format: "Wed Sep 05 2018"



browser console will provide suggestions for various methods of Date Object for extracting day, month, year, etc from the new Date()



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

Node.js puppeteer - Use values from array in a loop to cycle through pages