转换不带时区的日期格式-Google App脚本(Javascript),Google电子表格 [英] Convert date format without timezone - Google app script (Javascript), Google spreadsheet
问题描述
我正在研究Google电子表格和LINE Message API(BOT)之间的集成,其中Google应用程序脚本是后端.
I'm working on integration between Google spreadsheet and LINE Message API (BOT) where Google app script is back-end.
我从Google电子表格中获取了日期格式的单元格,并发送给LINE bot,但消息回复显示了另一回事. 在 Google Spreadsheet
I get the date-format cell from Google spreadsheet and send to LINE bot but the message reply showed different thing. in a cell of Google Spreadsheet
1/5/2020
在Google应用脚本中,我首先对其进行了编码
In Google app script, I first coded it
var colb = ss.getSheets()[0].getRange(i+3, 2).getValue();
但有LINE消息,它默认发送包含时区在内的格式
but LINE message, it sends format included timezone as default
2020年1月5日,星期日00:00:00 GMT + 0700(ICT)
所以我把它编码了
var colb = Utilities.formatDate(ss.getSheets()[0].getRange(i+3, 2).getValue(), ss.getSpreadsheetTimeZone(), "dd/MM/YY");
这是可行的,但是当单元格为空时它不起作用,我不知道为什么.所以有人请帮我.预先感谢
This one is works but it's not working when cell is empty which is I have no clue why. So someone please help me with this. Thank in advance
推荐答案
如果单元格为空,并且您想使用Utilities.formatDate,我会这样:
If cell is empty and you want to use Utilities.formatDate I would do like this:
var colb = " " || Utilities.formatDate(ss.getSheets()[0].getRange(i+3, 2).getValue(), ss.getSpreadsheetTimeZone(), "dd/MM/YY");
因此,如果单元格中没有值,则只需分配默认值"
So in case there is no value in cell just assign default value " "
这篇关于转换不带时区的日期格式-Google App脚本(Javascript),Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!