Tengo una cadena que está compuesta por cookies ingresadas por el usuario en un formulario. este es el codigo:
var monthCookie = getCookieValue("monthUserPref") var dayCookie = getCookieValue("dayUserPref") var hourCookie = getCookieValue("hourUserPref") var minuteCookie = getCookieValue("minuteUserPref") var ampmCookie = getCookieValue("ampmUserPref") var currentYear = new Date().getFullYear(); var monthCookie = getMonth(monthCookie); var currentEndDateForClockNoTZChange = "'"+currentYear+", "+monthCookie+", "+dayCookie+", "+hourCookie+", "+minuteCookie+", 0'" var endTimeNoOffset = new Date(currentEndDateForClockNoTZChange) var endTimeOffset = endTimeNoOffset.getTimezoneOffset(); alert("Put together time is "+currentEndDateForClockNoTZChange) alert(endTimeNoOffset) alert("month cookie reads '"+monthCookie+"', day cookie reads '"+dayCookie+"', hour cookie reads '"+hourCookie+"', minute cookie reads '"+minuteCookie+"', ampm cookie reads '"+ampmCookie+"'."); alert("timer offset is "+endTimeOffset) La primera alerta dice "Put together time is '2022, 1, 11, 1, 11, 0' " .
la segunda alerta dice Invalid Date" ,
la tercera alerta dice, month cookie reads '1' ,
day cookie reads '11' ,
hour cookie reads '1' ,
minute cookie reads '11' ,
ampm cookie reads 'PM'." ,
la cuarta alerta dice "Timer offset is NaN" .
¿Tengo que usar un formato diferente o algo así?
Por aquí:
la forma en que desea usar el constructor Date() se trata de argumentos de números enteros, no de una cadena
let monthCookie = Number(getCookieValue('monthUserPref')) , dayCookie = Number(getCookieValue('dayUserPref')) , hourCookie = Number(getCookieValue('hourUserPref')) , minuteCookie = Number(getCookieValue('minuteUserPref')) , ampmCookie = Number(getCookieValue('ampmUserPref')) , currentYear = new Date().getFullYear() , monthCookie = getMonth(monthCookie) , endTimeNoOffset = new Date( currentYear, monthCookie, dayCookie, hourCookie, minuteCookie, 0 ) , endTimeOffset = endTimeNoOffset.getTimezoneOffset() ;