Sanket Patel Sanket Patel - 1 year ago 97
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

Answer Source

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download