最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Avoid formatDate error in Google Apps Script - Stack Overflow

programmeradmin5浏览0评论

ive got a function to storage in an array and loop data from a document. Inside this one, there are cells with dates in format dd/mm/yyyy...but when I send it by email, appears like Wed Jan 01 2014 00:00:00 GMT-0300 (ART)

I used inside this function, a formatDate method but through me an error Cannot find method formatDate(string,string,string). How I can get the right formated date?

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;

}

ive got a function to storage in an array and loop data from a document. Inside this one, there are cells with dates in format dd/mm/yyyy...but when I send it by email, appears like Wed Jan 01 2014 00:00:00 GMT-0300 (ART)

I used inside this function, a formatDate method but through me an error Cannot find method formatDate(string,string,string). How I can get the right formated date?

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;

}
Share Improve this question asked Oct 20, 2014 at 13:01 user3911545user3911545 3092 gold badges4 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

You need to convert the string to date first before calling the formatDate() method.

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

评论列表(0)

  1. 暂无评论