Javascript:After Effects和Date()函数返回undefined

时间:2017-10-25 19:31:31

标签: javascript automation after-effects

情况就是这样。

  1. 我的团队制作了一个每周三播放的公告视频。介绍总是相同的,除了日期(文本层为“[Long Month] xx,20xx”)。
  2. 我正在尝试编写一些简单的自动化,使日期总是正确的星期三,无论出口日期如何(在星期三强制日期之前,星期三强制日期到 next <之后< / em>星期三)。
  3. 我的代码在浏览器中运行,但它在After Effects中不起作用。在AE中,它返回 undefined。帮助! (运行After Effects 14.2.1.34)

    var today, day, date, month
    
    today = new Date(Date(0));
    day = today.getDay();
    date = today.getDate();
    month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    
    
    function printDate() {
      return month[today.getMonth()] + " " + date + ", " + today.getFullYear();
    }
    
    
    function forceWednesday() {
      if (day === 3) {
        printDate();
      } else if (day < 3) {
        var x = day;
        x = 3 - day;
        return month[today.getMonth()] + " " + (date + x) + ", " + today.getFullYear();
      } else if (day > 3) {
        var dayDiff, dateDiff, nextWed, newDate, wed
        dayDiff = day - 3;
        dateDiff = date - dayDiff;
        nextWed = today.setDate(dateDiff + 7);
        newDate = new Date(nextWed);
        wed = newDate.getDate();
        return month[newDate.getMonth()] + " " + wed + ", " + newDate.getFullYear();
      }
    }
    
    forceWednesday();

1 个答案:

答案 0 :(得分:0)

修正了它。 See it live on Github.