Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python-将时间从x小时y分钟格式转换为z分钟_Python_Python 2.7_Python 3.x - Fatal编程技术网

python-将时间从x小时y分钟格式转换为z分钟

python-将时间从x小时y分钟格式转换为z分钟,python,python-2.7,python-3.x,Python,Python 2.7,Python 3.x,Google API以x小时y分钟为单位返回时间。我想将其转换为z分钟。获得这一结果的最佳方式是什么 来自Google API的响应示例: { "destination_addresses": [ "Hamburg, Germany" ], "origin_addresses": [ "85748 Garching, Germany" ], "rows": [ { "elements": [ { "dis

Google API以x小时y分钟为单位返回时间。我想将其转换为z分钟。获得这一结果的最佳方式是什么

来自Google API的响应示例:

{
  "destination_addresses": [
    "Hamburg, Germany"
  ],
  "origin_addresses": [
    "85748 Garching, Germany"
  ],
  "rows": [
    {
      "elements": [
        {
          "distance": {
            "text": "761 km",
            "value": 760831
          },
          "duration": {
            "text": "7 hours 1 min",
            "value": 25242
          },
          "duration_in_traffic": {
            "text": "6 hours 42 mins",
            "value": 24145
          },
          "status": "OK"
        }
      ]
    }
  ],
  "status": "OK"
}
预期产出:
流量“6小时42分钟”中的持续时间-->6*60+42=402分钟

我想您是在问如何将字符串值作为数字获取,以便进一步使用它

"duration_in_traffic": {
    "text": "6 hours 42 mins",
    "value": 24145
}
此处的值已经是数字,它表示秒数。 因此24145/60=402.416分钟

这部分工作是为你做的


现在您将如何处理这个值:)

我想您是在问如何将字符串值作为数字来获取,以便进一步使用它

"duration_in_traffic": {
    "text": "6 hours 42 mins",
    "value": 24145
}
此处的值已经是数字,它表示秒数。 因此24145/60=402.416分钟

这部分工作是为你做的


现在,您将如何处理该值:)

您好,非常感谢您的回答。我确切想要的是python代码如何返回该值——这意味着获取google的输出作为python的输入,并用简单的词返回该值——python cod如何获得该数据(google API)以及cod返回的所有内容:24145(在本例中)您好,非常感谢您的回答我想要的是python代码如何返回这个值——这意味着获取google的输出作为python的输入,并用简单的词返回这个值——python cod如何获得这个数据(google API)以及所有cod返回值:24145(在本例中)