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

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

问题描述

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

What would be the best way to compare two dates?

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 object具有 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天全站免登陆