比较两个日期 Google 应用程序脚本 [英] Compare two dates Google apps script

查看:22
本文介绍了比较两个日期 Google 应用程序脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比较两个日期的最佳方法是什么?

var int = e.parameter.intlistbox;
var startDate = rSheet.getRange(parseInt(int) + 1 ,1).getValues();
// returns Sat Jun 30 2012 00:00:00 GMT-0300 (BRT) 
var toDay = new Date();
// Sat Jun 23 2012 22:24:56 GMT-0300 (BRT)

if (startDate > toDay){ ....

我看到了 .toString() 选项,但这似乎只适用于 == 或 === 运算符.

I saw the .toString() option but that seems to work only for == or === operator.

这件事有什么清楚的吗?

Anything clear about this matter?

推荐答案

Date 对象具有 valueOf 方法,该方法返回自 1970-01 午夜以来的毫秒数-01.您可以使用它来比较日期.类似的东西

The Date object has the valueOf method which returns the number of milliseconds since midnight 1970-01-01. You can use it to compare dates. Something like

var date01 = new Date();
var date02 = new Date(2012, 5, 24);
if (date01.valueOf() > date02.valueOf()) {
   ....
}

这篇关于比较两个日期 Google 应用程序脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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