【问题标题】:Script Sheet : how to fix the time in 12hour (AM/PM) in google sheet脚本表:如何在谷歌表中修复 12 小时(上午/下午)的时间
【发布时间】:2021-09-10 00:44:42
【问题描述】:

可以帮助如何修复我的谷歌表中的代码 > 脚本 当我更改代码时,"HH:mm tt" 使用 TT 更改(上午/下午),但代码出错了..

这里是示例错误

Exception: Invalid argument: MMMM dd, yyyy, HH:mm tt
CONVERTDATE @ CONVERTDATE.gs:6

我的脚本在这里使用

function CONVERTDATE(date) {
  let time = new Date(date);
  let seconds = time.getTime();
  let addHours = 8 * 60 * 60 * 1000;
  let hoursLater = new Date(seconds + addHours);
  let converted = Utilities.formatDate(hoursLater,Session.getTimeZone(), "MMMM dd, yyyy, HH:mm tt")
  return converted;
}

希望这里的任何人都可以帮助我解决这个问题

谢谢

【问题讨论】:

    标签: google-apps-script google-sheets google-sheets-formula google-sheets-api spreadsheet


    【解决方案1】:

    试试

    tt改为a

    function CONVERTDATE(date) {
      let time = new Date(date);
      let seconds = time.getTime();
      let addHours = 8 * 60 * 60 * 1000;
      let hoursLater = new Date(seconds + addHours);        
      let converted = Utilities.formatDate(hoursLater,Session.getTimeZone(), "MMMM dd, yyyy, HH:mm a ")
      return converted;              
    }
    

    参考:

    【讨论】:

    • 谢谢它的工作原理...顺便说一句,如果 B 列在整行中插入自动日期和 C 列,当 B 列有数据时,如何使用此脚本作为自动添加到行中尝试遵循此公式,但获取转换日期时出错,=ArrayFormula(if(B2:B<>"",row(B2:B),""(CONVERTDATE($B2)))) 谢谢
    猜你喜欢
    • 2011-11-16
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2012-12-03
    • 1970-01-01
    相关资源
    最近更新 更多