Search code examples
javasolrdatetime-conversion

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 and i need to add 330 minutes to that date and display it


Solution

  • var userdate = new Date("2009-1-1T8:00:00Z");
    var timezone = userdate.getTimezoneOffset();
    var serverdate = new Date(userdate.setMinutes(userdate.getMinutes()+parseInt(timezone)));
    

    This will give you the proper UTC Date and Time. It's because the getTimezoneOffset() will give you the timezone difference in minutes. I recommend you that not to use toISOString() because the output will be in the string Hence in future you will not able to manipulate the date