Format Javascript date, find day of the week?

2

I have the following problem.

I have a data picker that gives me the value of the date like this: dd-mm-aaa (05-13-2016)

But I need to check which day of the week is ex: Today is Friday. The problem I can not check with this format.

I would have to get the value of the field and change it to use New Date () and getDay () to verify. Now how do I do this?

Or do I have to check with this same format?

Or how to use the toLocaleDateString method

I need to be in javascript not Jquery, I'm learning JS.

Hugs

    
asked by anonymous 13.05.2016 / 18:11

2 answers

1

My answer to the problem.

var str = campo.value,
    parts = str.split('-'),
    year = parseInt(parts[2], 10),
    month = parseInt(parts[1], 10) - 1,
    day = parseInt(parts[0], 10),
    date = new Date(year, month, day),
    dia = date.getDay();

if (dia == "6") {
    alert("Sábado ");
}
if (dia == "0") {
    alert(" Domingo");
};
    
14.05.2016 / 02:13
2
var from = $("#datepicker").val().split("-"); //(15-05-2016)
var f = new Date(from[2], from[1] - 1, from[0]);

Credits: link

    
13.05.2016 / 18:18