var str="2018-11-01";
var newstr = str.split('-').reverse().join('/');
console.log(newstr);
The split()
method divides a String object into an array of strings by separating the string into substrings
The reverse()
method reverses the items in an array. The first element of the array becomes the last and the last element becomes the first.
The join()
method joins all elements of an array into a string and returns this string.
If the separator in the join()
method is omitted the elements of the array are separated by a comma (","). If the separator is an empty string, all elements are joined without any characters between them
About Your Review
como eu faço para a data ir parar ai dentro desse parênteses sendo que
ela está digitada em um input do formulário?
With a JavaScript function
function myFunction() {
var str=document.getElementById("data1").value;
console.log(str);
var newstr = str.split('-').reverse().join('/');
console.log(newstr);
}
<input required type='date' name="data1" id="data1" class="form-control" />
<button onclick="myFunction()">Submit</button>
With Jquery
The focusout event fires once the element loses focus
var str = $("#data1");
str.focusout( function(){
//data retornada do input
console.log(str.val());
//data transformada
console.log(str.val().split('-').reverse().join('/'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputrequiredtype='date'name="data1" id="data1" class="form-control" />