如何使用if / else [英] how to use if / else

查看:104
本文介绍了如何使用if / else的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google脚本初学者,我需要一些帮助!
我有一个脚本在文件中导入数据,我想在日期中添加一个条件。



我的脚本如下:

  obj.participants [i] .create_date.replace(/(\ d {4}) - (\ d {2}) - (\ (\ d {2}):( \d {2})/,函数(p,year,mon,day,hour,min){
data [index] [3] = [day,mon,year - 2000] .join(/);
data [index] [4] = [hour,min] .join(h);
});
billet = obj.participants [i] .id_weez_ticket;
data [index] [31] = 15 + billet.substring(0,4);

我想根据data [index] [4]中的日期值更改最后一行:


  • if data [index] [4]<数据[index] [31] = 15 + billet.substring(0,4)
  • 0,4);


感谢您的协助!

解决方案

它会是这样的,但这不会工作,因为data [index] [4]将会是'[hh] h [mm]'形式的时间。

  if(data [index] [4]< 1/09/2015){

data [index] [31 ] = 15 + billet.substring(0,4);

} else {

data [index] [31] = 16 + billet.substring(0,4);
}

data [index] [3]包含日期,然后您必须将它们转换为时间对象,然后再进行毫秒的比较。

  var referenceDateMs = new Date(2015, 9,1).getTime()
var dateMs =(new Date(year,mon,day)).. getTime()

if(dateMs< referenceDateMs){

// ....

}其他{

// ....
}


I am a google script beginner and i need some help ! I have a script importing data in a file and I want to add a condition on the date.

My script below:

obj.participants[i].create_date.replace(/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})/, function(p, year, mon, day, hour, min) {
                data[index][3] = [day, mon, year - 2000].join("/");
                data[index][4] = [hour, min].join("h");
            });
billet = obj.participants[i].id_weez_ticket;
data[index][31] = 15+billet.substring(0,4);

I want to change the last line depending on the date value in data[index][4]:

  • if data[index][4] < 1/09/2015 then data[index][31] = 15+billet.substring(0,4)
  • else data[index][31] = 16+billet.substring(0,4);

Thank you for your help !

解决方案

It would be something like this, but this wouldn't work as data[index][4] is going to be a time in the form '[hh]h[mm]'.

if (data[index][4] < 1/09/2015) {

    data[index][31] = 15+billet.substring(0,4);

} else { 

   data[index][31] = 16+billet.substring(0,4);
}

data[index][3] contains the date, and then you'll have to convert them into time objects, and then into milliseconds before you can compare them.

var referenceDateMs = new Date(2015, 9, 1).getTime()
var dateMs = (new Date(year, mon, day))..getTime()

if (dateMs < referenceDateMs) {

    // ....

} else {

    // ....
}

这篇关于如何使用if / else的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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