简体   繁体   English

应用脚本日期格式问题

[英]APPS SCRIPT DATE FORMAT ISSUE

I'm trying to send a table from google sheets to gmail using apps script, i have multiple dates and i want to send in this format "dd-mm-yy", but the problem is that i need to use utilites.formatdate which coverts the cell into string, so when i try to send the email it diplays that the parameters dont match the method, i think this is because in some cells date could be not fullfilled, so theres nothing written in the cell, because of this error i cant send the email, if i write dates in the cells it works but there are cases when they are not fullfilled as i said, how can i solved this problem and send the email no matter if all the dates are filled or not?我正在尝试使用应用程序脚本将表格从谷歌表格发送到 gmail,我有多个日期,我想以这种格式“dd-mm-yy”发送,但问题是我需要使用 utilites.formatdate将单元格转换为字符串,因此当我尝试发送电子邮件时,它显示参数与方法不匹配,我认为这是因为在某些单元格中日期可能未填写,因此单元格中没有写入任何内容,因为此错误我无法发送电子邮件,如果我在单元格中写日期它可以工作,但有些情况下它们没有如我所说的那样填写,我如何解决这个问题并发送电子邮件,无论是否填写了所有日期?

var fecha = registro.getRange("c16").getValue();
var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");

This is the way i tried to change the format, and if there is someting written works but这是我尝试更改格式的方式,如果有一些书面作品,但

var fecha2 = registro.getRange("e16").getValue();
var fecha2F = Utilities.formatDate(fecha2, "GMT","dd-MM-YY");

In the second there is nothing so it displays the error在第二个没有什么所以它显示错误

Hope you can help me guys希望你们能帮助我伙计们

I'm learning so all kind of advices you give to me are welcome我正在学习所以欢迎你给我的各种建议

Try this:尝试这个:

var fecha = new Date(registro.getRange("c16").getValue());
var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");

Try to initiate Date by adding new DATE() to use the converted string as DATE type and after that you can format it as you want so your code will be尝试通过添加new DATE()来启动 Date 以使用转换后的字符串作为 DATE 类型,然后您可以根据需要对其进行格式化,以便您的代码

var fecha = new DATE(registro.getRange("c16").getValue());

EDIT编辑

 var fechaF = Utilities.formatDate(fecha, "GMT","dd-mm-yyyy").setNumberFormat('dd-mm-yyy');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM