json returns years in this format
I need to convert the years to this format
var bDate = "3/23/1997"; var bDateformat = new Date(bDate).getTime() / 1000 | 0; console.log("Birthday: "+bDateformat);
so in example i get returned value of
Juan Pablo Isaza
You can use this to output in JSON format:
var bDate = "3/23/1997"; new Date(bDate ).toJSON() // result: '1997-03-22T19:30:00.000Z'
Or you can use this to get the date object from the JSON string:
var bDate = '1997-03-22T19:30:00.000Z'; new Date(bDate).toLocaleString() // result: '3/23/1997, 12:00:00 AM'
This was also my question before, I have easily overcome this by using the Moment.js. It is easy to use and very understandable. Also, you can easily convert the patterns all together very simply.
var bDate = "1997-03-23T08:00Z" var newBDate = moment(bDate, "YYYY-MM-DDTHH:mm[Z]").format('M/DD/YYYY'); //Or you can use any other final date format as you want console.log(newBDate)
This will help users to easily convert to any time format they want.