如何从Google Spreadsheet读取正确的时间/持续时间值 [英] How to read the correct time/duration values from Google Spreadsheet

查看:98
本文介绍了如何从Google Spreadsheet读取正确的时间/持续时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从时间格式的Cell(hh:mm:ss)中获取小时值,该值可以更大,例如24:00:00,例如20000:00:00应该为20000:

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:

表格:

如果您阅读了E1的值:

if your read the Value of E1:

var total = sheet.getRange("E1").getValue();
Logger.log(total);

结果是:

4月12日星期六07:09:21 GMT + 00:09 1902

Sat Apr 12 07:09:21 GMT+00:09 1902

现在,我尝试将其转换为Date对象并获取其Unix时间戳:

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

1374127872020.000000

381702.1866722222

381702.1866722222

问题是如何获取正确的20000值?

The question is how to get the correct value of 20000 ?

推荐答案

有两个新函数getDisplayValue()getDisplayValues()可以返回日期时间或与电子表格上看起来完全相同的任何内容.在此处

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 Spreadsheet读取正确的时间/持续时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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