iMacros - 将日期设置为明天和后天

时间:2015-03-01 02:03:19

标签: imacros

我已经录制了一个iMacro,用于处理明天和后天两个下拉列表中的设置日期。但是使用它的人必须每天编辑宏以设置日期,包括明天或后天变化的月份。

我想知道imacro能否自动完成?将日期1设置为明天的日期和日期2至日后的日期。月份呢?如果从明天或后天开始的新月怎么办? imacro可以自己做一些常识性的决定吗? :)

1 个答案:

答案 0 :(得分:0)

此代码明天和后天输出。需要使用Javascript和iMacros命令EVAL。

var today = new Date(); 
var tomorrow = new Date(); 
tomorrow.setDate(today.getDate() + 1); 
var day = tomorrow.getDate().toString(); 
if (day.length < 2) {day = "0" + day;} 
var month = (tomorrow.getMonth() + 1).toString(); 
if (month.length < 2) {month = "0" + month;} 
var year = tomorrow.getFullYear().toString(); 
var tomorrowDateString = day + "/" + month + "/" + year; 

var afterTomorrow = new Date(); 
afterTomorrow.setDate(today.getDate() + 2); 
var day = afterTomorrow.getDate().toString(); 
if (day.length < 2) {day = "0" + day;} 
var month = (afterTomorrow.getMonth() + 1).toString(); 
if (month.length < 2) {month = "0" + month;} 
var year = afterTomorrow.getFullYear().toString(); 
var afterTomorrowDateString = day + "/" + month + "/" + year;

alert('tomorrow: '+tomorrowDateString+'  after tomorrow: '+afterTomorrowDateString);

对于iMacros,此代码如下所示:

SET tomorrow EVAL("var today = new Date(); var tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1); var day = tomorrow.getDate().toString(); if (day.length < 2) {day = \"0\" + day;} var month = (tomorrow.getMonth() + 1).toString(); if (month.length < 2) {month = \"0\" + month;} var year = tomorrow.getFullYear().toString(); var tomorrowDateString = day + \"/\" + month + \"/\" + year; tomorrowDateString;")
PROMPT {{tomorrow}}

SET afterTomorrow EVAL("var today = new Date(); var afterTomorrow = new Date(); afterTomorrow.setDate(today.getDate() + 2); var day = afterTomorrow.getDate().toString(); if (day.length < 2) {day = \"0\" + day;} var month = (afterTomorrow.getMonth() + 1).toString(); if (month.length < 2) {month = \"0\" + month;} var year = afterTomorrow.getFullYear().toString(); var afterTomorrowDateString = day + \"/\" + month + \"/\" + year; afterTomorrowDateString;")
PROMPT {{afterTomorrow}}