Google应用使用用户输入创建日期 [英] Google apps date creation from user input

查看:154
本文介绍了Google应用使用用户输入创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数onFormSubmit(e){

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

//如上所述的oncatenating字符串失败?

// ...表单然后发送电子邮件并将日期添加到Google日历中

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



问题是,如果我使用串联来构造字符串(因此输入可以接受4/4/2013)日期失败,无效的日期,当我给自己的电子邮件发送电子邮件的价值。

也许这很奇怪,但带有调试的电子邮件也带有前面的'好像它逃避价值或什么...

  var emailBody =预订查询是在+时间戳+ 

\\\
\\\
他们输入的详细信息如下:+

\\\
从:+ start +与原始日期输入:+ e.values [1] +

// etc

给出:
预订查询已完成on 11/04/2013 17:53:06



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



请参阅? '04/03/2013



更新



< ,但后来我发现'只有当Google Form托管在我的本地主机开发服务器上时才会出现'。当页面上线时(包含iFrame),那么子串删除技巧就不需要了,因为不会有前缀。

解决方案

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



您可以使用字符串运算符(如 substring()

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


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

I'm using a Google spreadsheet to store start, end, title value from a Google Form generated from that spreadsheet. I now want to add those values to a Google Calendar.

Problem is that if I use concatenation to construct the string (so input can accept 4/4/2013) the date fails, "Invalid Date" when I email myself the values.

Maybe this is weird, but the email with the debug also carries a preceding ' as if it is escaping the value or something ...

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

Gives: Booking enquiry was made on 11/04/2013 17:53:06

The details they entered were as follows: From: Invalid Date vs original date input : '04/03/2013

See? '04/03/2013

UPDATE

The reply of Serge insas worked, but subsequently I discovered the ' appears only when the Google Form is hosted on my localhost dev server. When the page is put online (containing the iFrame) then the substring removal trick is not needed as no ' is prepended.

解决方案

The ' is used in spreadsheet cells to keep values as strings. If it is removed the the spreadsheet would convert it to a date object.

You can easily remove that ' with a string operator like substring()

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

这篇关于Google应用使用用户输入创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆