首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于Google Sheets的脚本,将由Google Forms提供的时间戳转换为6-8位

用于Google Sheets的脚本,将由Google Forms提供的时间戳转换为6-8位
EN

Stack Overflow用户
提问于 2020-06-10 07:01:38
回答 1查看 59关注 0票数 1

GoogleForm是用于产品库存的。我在食品救援非盈利组织工作,是一名全职志愿者,所以我很抱歉自己这么傻。我已经制作了一个记录托盘信息的表单,我想使用时间戳来生成一个6位数(祈祷),我将使用它作为namedValues可安装触发器中“文本代码”和“#boxesonpallet”之间的“时间戳”?我发现(并希望我可以改变)

{‘名字’:‘简’,‘时间戳’:‘6/7/2015 20:54:13',’姓氏‘:doe` }

无论如何,我希望它能在提交时计算这个数字??(还必须学习如何做到这一点),然后像这样使用它…

{‘文本代码’:‘UHTMILK’,'6位数字‘:’671523‘,'#boxesonpallet':168` }

然后把它发回给我,这样我就可以在我的托盘上写代码,然后转到下一个。

显然,我将不得不学习如何获取表格响应表上的其余数据,并将其用于许多其他目的,但目前我需要20个小时来清点、填写订单和重新进货,而且我是唯一一个拥有叉车许可证的人,目前我们每周将20多个托盘转移到其他慈善组织,这太疯狂了。

你们能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2020-06-10 11:44:31

日期值转换为六位数代码,六位数代码返回到日期值

代码语言:javascript
复制
function datevaluetosixdigitcode(dv) {
  const  c=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  let html="";
  let chr={};
  c.forEach(function(ch,i){chr[i]=ch;})
  let t=Math.pow(62,1);
  let ts=Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"MM/dd/yyyy HH:mm:ss")
  let valueOf=new Date().valueOf();
  var dv=dv/1000||new Date().valueOf()/1000;
  let d5=Math.floor(dv/Math.pow(t,5));
  let r5=dv%Math.pow(t,5);
  let d4=Math.floor(r5/Math.pow(t,4));
  let r4=r5%Math.pow(t,4);
  let d3=Math.floor(r4/Math.pow(t,3));
  let r3=r4%Math.pow(t,3);
  let d2=Math.floor(r3/Math.pow(t,2));
  let r2=r3%Math.pow(t,2);
  let d1=Math.floor(r2/Math.pow(t,1));
  let r1=r2%Math.pow(t,1);
  let d0=Math.floor(r1/Math.pow(t,0));
  let code=Utilities.formatString('%s%s%s%s%s%s',chr[d5],chr[d4],chr[d3],chr[d2],chr[d1],chr[d0]);
  //html+=Utilities.formatString('radix:%s<br />valueOf:%s<br />TimeStamp:%s<br />Six Digit Code:%s%s%s%s%s%s<br />test: %s<br />TheOtherWay:%s',t,valueOf,ts,chr[d5],chr[d4],chr[d3],chr[d2],chr[d1],chr[d0],code,goingtheotherway(code))
  //SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Display");
  return code;
}


function sixdigitcodetodatevalue(code) {
  const  c=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  var code=code||'1JIRIR';
  let idx={};
  let html="";
  c.forEach(function(chr,i){idx[chr]=i});
  let cA=code.split("").reverse();
  let valueOf=cA.reduce(function(a,c,i){
    a.total+=idx[c]*Math.pow(a.radix,i);
    return a;
  },{radix:62,total:0,valueOf:function(){return this.total*1000;}}).valueOf();
  html=Number(valueOf).toFixed(0);
  //SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Display")
  return valueOf;
}

function dttesting() {
  let dt=new Date();
  let dts=Utilities.formatDate(dt, Session.getScriptTimeZone(), "MM/dd/yyyy HH:mm:ss");
  let code=datevaluetosixdigitcode(dt.valueOf());
  let val=sixdigitcodetodatevalue(code);
  let fdts=Utilities.formatDate(new Date(val), Session.getScriptTimeZone(), "MM/dd/yyyy HH:mm:ss");
  let html=Utilities.formatString('dts: %s<br />code: %s<br />fdts:%s ',dts,code,dts);
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Display");
}

function timestamptodatevalue(ts) {
  return new Date(ts).valueOf();
}

测试显示:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62293253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档