以两种不同的格式比较时间戳 - 气体 [英] Compare timestamp in two different formats - GAS

查看:275
本文介绍了以两种不同的格式比较时间戳 - 气体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用由Mogsdad发布的增强型工作流脚本这里



我已经设法解决了一些问题,但是我坚持目前是本节出现的错误 -

  //在电子表格中记录批准或拒绝
var row = ArrayLib.indexOf(data,0,timestamp);
if(row< 0)throw new Error(Request not available。); //如果未找到请求,则抛出错误
sheet.getRange(row + 1,approvalCol).setValue(e.parameter.approval);

我收到请求不可用错误,因为ArrayLib.indexOf对象正在比较时间戳来自相同的来源,但通过两个不同的路线。



'timestamp'变量的时间戳如下:17/03/2015 18: 00:11



...和'data'变量中包含的时间戳(应该与时间戳变量相匹配)看起来像这样 - 2015年3月17日00 00 :30:10 GMT-0700(PDT)。



我假设两种不同的格式是导致ArrayLib.indexOf对象返回'-1 / b>

任何关于我需要做什么以使匹配工作成功的想法?

解决方案

为时间戳记值创建一个新的Date对象,以便确保可以比较它们。代码应该如下所示:

  var dateFromTimestamp = new Date(timestamp); 


I am using the enhanced workflow script that was posted by Mogsdad here.

I have managed to work out a few issues but one that I am stuck on at the moment is the error that comes up from this section -

// Record approval or rejection in spreadsheet
  var row = ArrayLib.indexOf(data, 0, timestamp);
  if (row < 0) throw new Error ("Request not available.");  // Throw error if request was not found
  sheet.getRange(row+1, approvalCol).setValue(e.parameter.approval);

I get the "Request not available" error because the ArrayLib.indexOf object is comparing the time stamp that is being presented from the same source but via two different 'routes'.

The timestamp from the 'timestamp' variable looks like this - "17/03/2015 18:00:11"

...and the timestamp contained in the 'data' variable (that should match the timestamp variable) looks like this - "Tue Mar 17 2015 00:30:10 GMT-0700 (PDT)".

I am assuming that the two different formats is what is resulting in the ArrayLib.indexOf object returning a '-1' result and hence the error message.

Any thoughts on what I need to do to get the matching working successfully ?

解决方案

Create a new Date object for the timestamp value, so that you can ensure they can be compared. The code should look like:

  var dateFromTimestamp = new Date(timestamp);

这篇关于以两种不同的格式比较时间戳 - 气体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆