避免Google Apps脚本中的formatDate错误

问题描述:

我得到了一个函数来存储数组并循环来自文档的数据。 在这个里面,有格式为dd/mm/yyyy的单元格...但是当我通过电子邮件发送它时,出现像Wed Jan 01 2014 00:00:00 GMT-0300(ART)避免Google Apps脚本中的formatDate错误

我在这个函数里面使用了formatDate方法,但是通过我的一个错误 找不到方法formatDate(string,string,string)。 我如何才能得到正确的日期?

function getUsersExpDate(usersExpDate) { 

    var expDateArray = []; 

    var temp = usersExpDate[0]; 

    for(var n=0; n < usersExpDate.length; n++){ 

    expDateArray.push(usersExpDate[n]);  
    temp = usersExpDate[n]; 
    temp = Utilities.formatDate(temp, "GMT", "yyyy-MM-dd"); 

    } 

    return expDateArray; 

} 

在调用formatDate()方法之前,您需要先将字符串转换为日期。

temp = new Date(usersExpDate[n]); 
temp = Utilities.formatDate(temp, "GMT", "yyyy-MM-dd");