2012-06-22 14 views
0

我有一個數組,我想使用getRange()。setValues()寫入電子表格。我能夠寫入電子表格中沒有問題,但日期八方通是這樣的:無法在數組中格式化日期

2012-06-18T07:00:00.000Z

我只看到2012-06-18感興趣。當我嘗試使用

passedArray[0][12] = Utilities.formatDate(passedArray[0][12], "GMT", "yyyy-MM-dd"); 

Utilities.formatDate(passedArray[0][12], "GMT", "yyyy-MM-dd"); 

ModifiedArray[0][12] = Utilities.formatDate(passedArray[0][12], "GMT", "yyyy-MM-dd"); 

它產生意外的錯誤格式化的日期。其自被創建,並且在另一個功能填充的陣列,然後存儲在JSON格式的屬性:

var array1JSON = [{'array':[array1[i]]}]; 
UserProperties.setProperty("arrayPassing",JSON.stringify(array1JSON)); 

然後從另一功能

var array1JSON = JSON.parse(UserProperties.getProperty('arrayPassing')); 
var passedArray = array1JSON[0].array; 

任何幫助,將理解的訪問。

謝謝!

回答

1

我想你可以試試Utilities.formatDate(new Date(passedArray[0][12]), "GMT", "yyyy-MM-dd"); 因爲Utilities.formatDate中的參數必須是日期對象。