以两种不同的格式比较时间戳

编程入门 行业动态 更新时间:2024-10-13 10:29:47
本文介绍了以两种不同的格式比较时间戳 - 气体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用由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);

更多推荐

以两种不同的格式比较时间戳

本文发布于:2023-11-30 16:02:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两种   格式   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!