Sanket Patel Sanket Patel - 3 months ago 28
Java Question

How to Convert solr date to javascript date?

i am having the time in "2016-11-17T09:22:24Z" and i need to convert it into
"2016-11-1709:22:24".Just need to remove T and Z from solr Date


First we can construct a javascript date object from the string and then you can convert it into correct format:

var dt = new Date('2016-11-17T09:22:24Z')
var formattedDate = dt.toISOString().substring(0, 19).replace('T', '')

console.log(formattedDate) should log 2016-11-1709:22:24

Or in one line:

new Date('2016-11-17T09:22:24Z').toISOString().substring(0, 19).replace('T', '')

will render: 2016-11-1709:22:24

Some more good discussions here: Convert javascript to date object to mysql date format (YYYY-MM-DD)