How to convert a date (string) to another format using JavaScript?

0

I have the following string:

2016-06-08 - 10:08 

I need to convert this string to the other format:

08-06-2016 10:08

How do I proceed?

   function dateFormat(date) {
      inputFormat = new java.text.SimpleDateFormat('dd-MM-yyyy');
      inputText = "2012-11-17";
      date = inputFormat.parse(inputText);
      outputText = inputFormat.format(date);
      alert(outputText);
        };
    
asked by anonymous 08.06.2016 / 19:12

2 answers

1

If your string follows the same pattern, you can change the position of the letters

var datas = "2016-06-08 - 10:08 ";
var novaData = (datas[8]+datas[9]+datas[4]+datas[5]+datas[6]
+datas[7]+datas[0]+datas[1]+datas[2]+datas[3]+datas[10]+datas[11]
+datas[12]+datas[13]+datas[14]+datas[15]+datas[16]+datas[17]);
alert(novaData);

link

    
08.06.2016 / 21:20
1

Why do not you use the split method to separate the date by the separator - and store it in a vector and then only use the reverse () method to invert the array e.e ...

    
09.06.2016 / 02:21