【问题标题】:Google apps date creation from user input根据用户输入创建 Google 应用程序日期
【发布时间】:2013-04-11 16:19:25
【问题描述】:
function onFormSubmit(e) {

  var d = e.values[1] + " 10:00:00 UTC";
  var start = new Date(d);

  // oncatenating the string as above fails?   

// ... form then sends an email and adds date to a Google Calendar

我正在使用 Google 电子表格存储从该电子表格生成的 Google 表单的开始、结束、标题值。我现在想将这些值添加到 Google 日历中。

问题是,如果我使用串联来构造字符串(因此输入可以接受 2013 年 4 月 4 日),日期将失败,当我通过电子邮件向自己发送值时“日期无效”。

也许这很奇怪,但是带有调试的电子邮件还带有前面的 ' 好像它正在转义值或其他东西......

var emailBody = "Booking enquiry was made on " + timestamp +

  "\n\nThe details they entered were as follows: " +

  "\nFrom: " + start +  " vs original date input : " +  e.values[1] + 

   // etc

提供: 预订查询于 11/04/2013 17:53:06 进行

他们输入的详细信息如下: 来自:无效日期与原始日期输入:'04/03/2013

看到了吗? '04/03/2013

更新

Serge insas 的回复有效,但后来我发现 ' 仅在 Google 表单托管在我的本地主机开发服务器上时才会出现。当页面上线时(包含 iFrame),则不需要子字符串删除技巧,因为前面没有 '。

【问题讨论】:

    标签: date google-apps-script google-calendar-api


    【解决方案1】:

    ' 用于电子表格单元格中以将值保存为字符串。如果它被删除,电子表格会将其转换为日期对象。

    您可以使用 substring() 等字符串运算符轻松删除 '

    var withoutQuote = e.values[1].substring(1);
    

    【讨论】:

    • 谢谢,这正如你所解释的那样工作。所以要欣赏的是表单提交中的数据是在数据放入电子表格之后完成的,然后从中读取。这可以解释我的问题,我很高兴我的问题中关于奇怪的 ' 行!
    猜你喜欢
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    • 2021-08-30
    • 1970-01-01
    相关资源
    最近更新 更多