Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何在Google脚本中分割时间戳并将其作为整数保存?_Google Apps Script_Google Sheets_Google Sheets Api - Fatal编程技术网

Google apps script 如何在Google脚本中分割时间戳并将其作为整数保存?

Google apps script 如何在Google脚本中分割时间戳并将其作为整数保存?,google-apps-script,google-sheets,google-sheets-api,Google Apps Script,Google Sheets,Google Sheets Api,因此,我在第一列有一个带有时间戳的谷歌表,如: row:1 12/19/2019 1:11:19 ro2:2 1/21/2020 0:16:13 当我使用Logger.log(日期)时;我得到: 我试图将月、日和年分成不同的变量,但将它们作为整数保存。 这是我分割字符串的唯一方法,但我找不到将日和月保持为整数的方法 var date = sheet.getRange(2,1).getValue(); var month = date.slice(0, 4);//I get the

因此,我在第一列有一个带有时间戳的谷歌表,如:

row:1    12/19/2019 1:11:19
ro2:2    1/21/2020 0:16:13
当我使用Logger.log(日期)时;我得到:

我试图将月、日和年分成不同的变量,但将它们作为整数保存。 这是我分割字符串的唯一方法,但我找不到将日和月保持为整数的方法

var date = sheet.getRange(2,1).getValue();
var month = date.slice(0, 4);//I get the day as in Thur
我想知道是否有一个函数可以将日期和月份保持为数字,而不转换为字符串

function dt() {
  var today=new Date();
  var year=today.getFullYear();//4 digit year
  var month=today.getMonth()+1;//January=1
  var day=today.getDate();//sunday=0 to  saturday=6
  var dts="1/20/2020";
  var slash1=dts.indexOf('/');
  var m=Number(dts.slice(0,slash1));
  var slash2=dts.indexOf('/',slash1+1);
  var d=Number(dts.slice(slash1+1,slash2));
  var y=Number(dts.slice(slash2+1));
  var end="isnear";//Run the debugger all the down to here and you can see all of the answers at one time.
}
function dt() {
  var today=new Date();
  var year=today.getFullYear();//4 digit year
  var month=today.getMonth()+1;//January=1
  var day=today.getDate();//sunday=0 to  saturday=6
  var dts="1/20/2020";
  var slash1=dts.indexOf('/');
  var m=Number(dts.slice(0,slash1));
  var slash2=dts.indexOf('/',slash1+1);
  var d=Number(dts.slice(slash1+1,slash2));
  var y=Number(dts.slice(slash2+1));
  var end="isnear";//Run the debugger all the down to here and you can see all of the answers at one time.
}