如何使用 Google Apps 脚本重新格式化二维数组中的日期?

How to reformat dates in two dimensional arrays with Google Apps Script?

在下面的代码中,我想重新格式化日期,即每个内部数组中的第一个元素,以便在 Google Apps 脚本的输出中获取它们。我怎样才能做到这一点?谢谢!

function test() {
  const input = [['Fri Oct 15 2021 00:00:00 GMT-0400 (Eastern Daylight Time)', 123.19],
  ['Thu Oct 14 2021 00:00:00 GMT-0400 (Eastern Daylight Time)', 122.83]];

  // How should this code be changed to reformat the dates in each inner array to get the output like below
  var output = input.map(el => el);
  // output = [['Oct 15, 2021', 123.19],
  // ['Oct 14, 2021', 122.83]];
}

要将日期转换为所需的形式,可以使用.toLocaleDateString("en-US", options)方法

function test() {
  const input = [['Fri Oct 15 2021 00:00:00 GMT-0400 (Eastern Daylight Time)', 123.19],
  ['Thu Oct 14 2021 00:00:00 GMT-0400 (Eastern Daylight Time)', 122.83]];

  let options = { year: 'numeric', month: 'short', day: 'numeric' };

  // How should this code be changed to reformat the dates in each inner array to get the output like below
  var output = input.map(el => [(new Date(el[0])).toLocaleDateString("en-US", options),el[1]]);
  console.log(output)
  // output = [['Oct 15, 2021', 123.19],
  // ['Oct 14, 2021', 122.83]];
}