简体   繁体   English

如何将时间格式转换为数字格式(Google Sheets/Data Studio)

[英]How to convert time format to a number format (Google Sheets/Data Studio)

I want to convert the numbers in ColA to normal numbers, like the ones I have in ColB.我想将 ColA 中的数字转换为普通数字,就像我在 ColB 中的数字一样。 The one in ColA currently are in this format: 00:56:00.000. ColA 中的当前格式为:00:56:00.000。 I initially started out with a time length, that I then converted to seconds (what's currently in ColA).我最初以时间长度开始,然后将其转换为秒数(目前在 ColA 中)。 I need to convert them back into a single number to import into Data Studio so it can read it as time.我需要将它们转换回单个数字以导入 Data Studio,以便它可以按时间读取。 If I try to change the formatting to a number it comes up as a decimal, how can I change the format to a number?如果我尝试将格式更改为小数形式的数字,如何将格式更改为数字? Or can I do it in Data Studio?或者我可以在 Data Studio 中完成吗?

https://docs.google.com/spreadsheets/d/1xaAfc6hcFJJ1JsPfrx9Ly3usfljuzELT80UsgSxcNM8/edit#gid=0 https://docs.google.com/spreadsheets/d/1xaAfc6hcFJJ1JsPfrx9Ly3usfljuzELT80UsgSxcNM8/edit#gid=0

Try this on col B3 on Google Sheets while A3:A is converted into number format (in decimals):A3:A转换为数字格式(小数)时,在 Google 表格的B3列上尝试此操作:

=Arrayformula((A3:A*3600)*24)

Output: Output:

在此处输入图像描述

Explanation:解释:

This is just an observation, but it seems that Google Data Studio strictly follows the formatting of the cell values.这只是一个观察,但 Google Data Studio 似乎严格遵循单元格值的格式。 If you want to read the seconds as integers, a few arithmetic operations was performed to convert the number formatting of duration as such presented above.如果您想将秒数读取为整数,则执行一些算术运算以转换上述持续时间的数字格式。

Apps Script (use this if removing helper column B): Apps 脚本(如果删除辅助列 B,则使用此脚本):

function myFunction() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var data = ss.getRange('A3:A').getValues();

  Logger.log(data);

  var second = 3600;
  var hour = 24;
  var output = data.map(x => [x[0] * second * hour]);
  ss.getActiveSheet().getRange(3, 1, output.length, output[0].length).setValues(output);
}

Output: Output:

在此处输入图像描述

Change format to seconds only.将格式更改为仅秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google 表格 Python batchUpdate repeatCell -> 范围和数字格式问题 - Google Sheets Python batchUpdate repeatCell -> issue with range and number format Google Data Studio饼图JSON格式? - Google Data Studio pie chart JSON format? 在 Google Data Studio 中更改指标格式 - Change metric format in Google Data Studio Big Query 数据在导出到 Google 表格时会更改格式 - Big Query data changes format when exported to Google Sheets 谷歌数据工作室,解析日期不适用于 %Y%W 格式 - google data studio, parse date not working on %Y%W format 将文本(ISO 8601 格式的日期)转换为日期时间 - Data Studio - Convert Text(Date in ISO 8601 format) to DateTime - Data Studio 如何以有序的格式保存日期和时间 Firebase & Android Studio - How to save date and time in an orderly format Firebase & Android Studio 将 IST 格式的日期和时间合并并转换为 UTC 格式 - Merge and convert date and time in IST format to UTC format 如何将 python 中的时间戳转换为日期时间格式以获得 cosmos 数据? - How do I convert timestamp to datetime format in python for cosmos data? 如何在 Google Data Studio 中将文本类型转换为日期类型? - How to Convert Text type to Date type in Google Data Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM