[英]How to slice a timestamp and keeping it as integers in Google Scripts?
So I have a google sheet with Timestamps in the first column like:所以我在第一列中有一个带有时间戳的谷歌表,例如:
row:1 12/19/2019 1:11:19
ro2:2 1/21/2020 0:16:13
When I use Logger.log(date);当我使用 Logger.log(date); I get:
我得到:
Thu Dec 19 2019 01:11:18 GMT-0800 (PST)
I am trying to get the month, day and year into separate variables, but keep them as integers.我试图将月、日和年放入单独的变量中,但将它们保留为整数。 This is the only way I can slice the string, but I can't find ways to keep the day and month as integers.
这是我可以对字符串进行切片的唯一方法,但是我找不到将日期和月份保留为整数的方法。
var date = sheet.getRange(2,1).getValue();
var month = date.slice(0, 4);//I get the day as in Thur
I was wondering if there is a function to keep the day and month as numbers and not be converted to strings.我想知道是否有一个函数可以将日期和月份保留为数字而不是转换为字符串。
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.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.