getvalues() returns a complete date in the year 1899 for a cell containing only time

≡放荡痞女 提交于 2020-01-30 11:58:05

问题


If we have only a time in say cell A1 of Google sheets. For example, I have this:

8:09:00 AM

When I use this to fetch the contents of the cell: sheet.getRange(1, 1).getValue(); this is what it returns:

Sat Dec 30 1899 08:09:00 GMT-0500 (EST)

Why is this happening? Any way for getvalue() to stop interpreting the data and get the raw data instead?

Note: No special formatting has been set by me for the cell. So I guess the formating is the default (automatic), which is not something I want to change for every cell containing such data. The cells containing such times will not be known apriori in any case.


回答1:


Use range.getDisplayValue() to get the display value as a string.

More details on this can be found here: Difference between getValue() and getDisplayValue() on google app script

In short, getvalues returns an object which can be a number,a date or a string. In this case it returns a date object, which why it get formatted differently.



来源:https://stackoverflow.com/questions/42383165/getvalues-returns-a-complete-date-in-the-year-1899-for-a-cell-containing-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!