getvalues()返回仅包含时间的单元格在1899年的完整日期 [英] getvalues() returns a complete date in the year 1899 for a cell containing only time

查看:66
本文介绍了getvalues()返回仅包含时间的单元格在1899年的完整日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果说Google表格的A1单元格只有一个时间.例如,我有这个:

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

8:09:00 AM

当我使用它来获取单元格的内容时:sheet.getRange(1,1).getValue();这是它返回的内容:

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)

为什么会这样?有什么方法让getvalue()停止解释数据并取而代之的是原始数据?

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.

推荐答案

使用 range.getDisplayValue()获取显示值作为字符串.

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

有关此问题的更多详细信息,请参见:google app脚本上的getValue()和getDisplayValue()

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

简而言之,getvalues返回一个对象,该对象可以是数字,日期或字符串.在这种情况下,它返回一个日期对象,这就是为什么它采用不同的格式.

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.

这篇关于getvalues()返回仅包含时间的单元格在1899年的完整日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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