如何从 Google 电子表格中读取正确的时间/持续时间值 [英] How to read the correct time/duration values from Google Spreadsheet
问题描述
我试图从时间格式的单元格 (hh:mm:ss) 中获取小时值,值可以更大 24:00:00 例如 20000:00:00 应该给 20000:
表格:
如果您阅读了 E1 的值:
var total = sheet.getRange("E1").getValue();记录器.日志(总计);
结果是:
<块引用>4 月 12 日星期六 07:09:21 GMT+00:09 1902
现在我尝试将其转换为 Date 对象并获取它的 Unix 时间戳:
var date = new Date(total);var milsec = date.getTime();Logger.log(Utilities.formatString("%11.6f",milsec));var 小时 = milsec/1000/60/60;记录器.log(小时)
<块引用>
1374127872020.000000
381702.1866722222
问题是如何获得 20000 的正确值?
有两个新函数 getDisplayValue()
和 getDisplayValues()
可以准确返回日期时间或任何内容它在电子表格上的显示方式.在此处
I'm trying to get from a time formatted Cell (hh:mm:ss) the hour value, the values can be bigger 24:00:00 for example 20000:00:00 should give 20000:
Table:
if your read the Value of E1:
var total = sheet.getRange("E1").getValue();
Logger.log(total);
The result is:
Sat Apr 12 07:09:21 GMT+00:09 1902
Now I've tried to convert it to a Date object and get the Unix time stamp of it:
var date = new Date(total);
var milsec = date.getTime();
Logger.log(Utilities.formatString("%11.6f",milsec));
var hours = milsec / 1000 / 60 / 60;
Logger.log(hours)
1374127872020.000000
381702.1866722222
The question is how to get the correct value of 20000 ?
There are two new functions getDisplayValue()
and getDisplayValues()
that returns the datetime or anything exactly the way it looks to you on a Spreadsheet. Check out the documentation here
这篇关于如何从 Google 电子表格中读取正确的时间/持续时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!