如果該值不在一行中,我正在嘗試設定一個輸入值。我可以獲取行的值并設定值。
當我詢問輸入是否在行中時,出現了我的問題。這是我的腳本:
//Auxiliar Funtion
function is_in_array(array,value) {
is_in = false
Logger.log('This is the value: ' value)
for (i = 0; i < array.length; i ) {
Logger.log('This is i: ' array[i])
if (value == array[i]) {
is_in=true;
Logger.log('I was here!')
}
}
return is_in
}
//Main
function rm(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getActiveSheet();
var fecha = ws.getRange(5,9).getValue();
//Reviso si existe la fecha
ws = ss.getSheetByName(tipo);
numCols = ws.getLastColumn();
fechas = ws.getRange(1,4,1,numCols).getValues()[0];
Logger.log('Fecha :' fecha);
Logger.log('Fechas: ' fechas);
is_in_result = is_in_array(fechas, fecha)
Logger.log('Functions result: ' is_in_result)
//Logger.log(ArrayUtils.contains( fechas, fecha ))
if (is_in_result==true) {
Logger.log('If statement')
return True
} else {
Logger.log('Else Statement')
//Se a?ade la fecha
ws.getRange(1,numCols 1).setValue(fecha)
}
}
這是日志:
Registros de Cloud
9 ene 2022, 23:51:54 Información Fecha :Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información Fechas: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental),Fri Oct 15 2021 03:00:00 GMT-0400 (hora de verano oriental),Wed Dec 08 2021 03:00:00 GMT-0500 (hora estándar oriental),,,
9 ene 2022, 23:51:54 Información This is the value: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información This is i: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información This is i: Fri Oct 15 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información This is i: Wed Dec 08 2021 03:00:00 GMT-0500 (hora estándar oriental)
9 ene 2022, 23:51:54 Información This is i:
9 ene 2022, 23:51:54 Información This is i:
9 ene 2022, 23:51:54 Información This is i:
9 ene 2022, 23:51:54 Información Functions result: false
9 ene 2022, 23:51:54 Información Else Statement
Fecha 在 Fechas 中,所以函式結果必須為 true,但它回傳 false :(
我的錯誤在哪里?或者,有更簡單的方法來獲得相同的結果?也許它不起作用,因為我正在比較兩個日期,我不知道......
有些東西是西班牙語,對不起
uj5u.com熱心網友回復:
You can't compare different Date objects with == or ===. Compare them by their milliseconds since Unix Epoch with Date.getTime()
var date1 = new Date( '2022-01-01' );
var date2 = new Date( '2022-01-01' );
console.log( 'date1 == date2: ' ( date1 == date2 ) ); // false
console.log( 'date1 === date2: ' ( date1 === date2 ) ); // false
console.log( 'date1.getTime() == date2.getTime(): ' ( date1.getTime() == date2.getTime() ) ); // true
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/407475.html
標籤:
上一篇:回傳上一頁-Laravel8專案
下一篇:是否可以快取Mysql視圖?
