从Google Apps脚本中的日期中删除时间戳 [英] Remove timestamp from date in Google Apps Script
问题描述
我正在使用它来获取电子表格更新时创建的单元格的日期值:
I'm using this to snag a date value for cells that are created when a spreadsheet updates:
setValue(new Date()).setNumberFormat('MM/dd/yyyy')
但是我得到的回报包括时间戳(即2015年10月31日22:16:55),而不只是日期(2015年10月31日)。
But what I get back includes the timestamp (i.e. 10/31/2015 22:16:55), rather than just the date (10/31/2015).
这会导致我使用的引用该单元格的逻辑出现问题。逻辑是仅引用日期的基本 countif
语句。我可以调整以处理 timestamp
,但是我宁愿没有 timestamp
。似乎很基本,但我找不到任何解决方案。我缺少什么?
This creates a problem with the logic I'm using that references that cell. The logic is a basic countif
statements that references date only. I could adjust to deal with timestamp
but I would rather just not have the timestamp
. Seems basic but I couldn't find any solution. What am I missing?
推荐答案
格式不会改变日期值仍包含不同时间的事实。
The format won't change the fact that the date value is still containing the different times.
要从日期值本身截断时间,请尝试以下操作:
To truncate the time from the date value itself try the following:
setValue(new Date(new Date().setHours(0,0,0,0))).setNumberFormat('MM/dd/yyyy');
这篇关于从Google Apps脚本中的日期中删除时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!