Skip to content
Advertisement

How To Convert String ‘ dd/mm/yy hh:MM:ss ‘ to Date in javascript?

I have Done this

    var d='dd/mm/yy hh:MM:ss';
    var d1=d.split(" ");
    var date=d1[0].split("/");
    var time=d1[1].split(":");
    var dd=date[0];
    var mm=date[1]-1;
    var yy=date[2];
    var hh=time[0];
    var min=time[1];
    var ss=time[2];
    var fromdt= new Date("20"+yy,mm-1,dd,hh,min,ss);

Is there Any way to do it using JQuery OR JavaScript?

Advertisement

Answer

If you are looking for alternatives in jquery or Javascript , then you can go with Moment.js,where you can Parse, Validate, Manipulate, and Display dates in JavaScript.

example:

  var date= moment("06/06/2015 11:11:11").format('DD-MMM-YYYY');
Advertisement