Did you fail to declare this variable?

0

Good day I want to declare this but it turns out that the date type is ambiguous to which this error should be generated?

Ha tenido lugar un error en la línea: [43] The type Date is ambiguous
40:             mes=Integer.parseInt(fecha.substring(3, 5))-1;
41:             anio=Integer.parseInt(fecha.substring(6, 10));
42:    
43:         startDate: new Date(anio, mes, dia);
44:         endDate: new Date(anio, mes, dia);
    
asked by David Melo 16.04.2018 в 22:58
source

1 answer

0

There are some syntax errors in your code regarding the use of parseInt .

Also, if you have a date string in this format: 16-04-2018 , it is convenient to use split to obtain the different elements that will be part of the date.

Here I show you two ways to create a valid Date object:

/* Variables con las que vamos a trabajar */
var fecha = "16-04-2018";
var arrFecha = fecha.split("-");
var yyyy  = parseInt(arrFecha[2]);
var mm    = parseInt(arrFecha[1]) - 1;
var dd    = parseInt(arrFecha[0]);

/* Forma 1: */
var starDate = new Date(yyyy, mm, dd);
alert("Start: " + starDate);

/* Forma 2: */
const [dia, mes, anio] = fecha.split("-");
var endDate = new Date(anio, mes - 1, dia);
alert("End: " + endDate);
    
answered by 16.04.2018 в 23:45