久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何求和 N 次(HH:MM 格式)?

How to sum N number of time (HH:MM Format)?(如何求和 N 次(HH:MM 格式)?)
本文介紹了如何求和 N 次(HH:MM 格式)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在使用以下示例代碼來計算兩個不同時間值的總和.現在我想得到 N 個時間值的總和.

I am using the following sample code to calculate sum of two different time values. Now I want to get the sum of N number of time values.

// numbers for testing
$o="12:59";
$p="0:58";

// display for testing
echo "$o<br />";
echo "$p<br />";
echo AddPlayTime($o,$p);

// FUNCTION - ADD HOURS and MINUTES
function AddPlayTime ($oldPlayTime, $PlayTimeToAdd) {
  $old=explode(":",$oldPlayTime);
  $play=explode(":",$PlayTimeToAdd);

  $hours=$old[0]+$play[0];
  $minutes=$old[1]+$play[1];

  if($minutes > 59){
    $minutes=$minutes-60;
    $hours++;
  }

  if($minutes < 10){
    $minutes = "0".$minutes;
  }

  if($minutes == 0){
    $minutes = "00";
  }

  $sum=$hours.":".$minutes;
  return $sum;
}

推薦答案

這應該滿足您的要求:

$times 是時間數組,你可以添加你想要的時間

$times is the array of times and you can add how many time you want

$times = array();

$times[] = "12:59";
$times[] = "0:58";
$times[] = "0:02";

// pass the array to the function
echo AddPlayTime($times);

function AddPlayTime($times) {
    $minutes = 0; //declare minutes either it gives Notice: Undefined variable
    // loop throught all the times
    foreach ($times as $time) {
        list($hour, $minute) = explode(':', $time);
        $minutes += $hour * 60;
        $minutes += $minute;
    }

    $hours = floor($minutes / 60);
    $minutes -= $hours * 60;

    // returns the time already formatted
    return sprintf('%02d:%02d', $hours, $minutes);
}

編輯

我用正確的變量名稱編輯了代碼.現在更正確了.

I edited the code with the right names of the variables. It is more correct now.

希望這有幫助:-)

這篇關于如何求和 N 次(HH:MM 格式)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 精品国产91| av中文字幕在线 | 91视频一区二区三区 | 99色视频| 国产三级在线观看播放 | 日本91av视频| 欧美在线一区视频 | 日本精品一区二区三区四区 | 波波电影院一区二区三区 | 91精品国产一区二区三区 | 国产日韩一区二区三区 | 中文字幕一区二区在线观看 | 欧美一级在线观看 | 999免费视频 | 色播99| 国产精品美女视频 | 黄色一级片视频 | 欧美精品一区二区三 | 久久国产精品99久久久久 | 国产视频在线观看一区二区三区 | 日韩一区二区三区在线 | 婷婷久久综合 | 日本久久久久久久久 | 日日淫 | 成人免费视频7777777 | 精品久久久久久久久久久久 | 亚洲日本激情 | a免费视频 | 成人影院在线视频 | 日韩视频精品在线 | 一区二区三区中文字幕 | 亚洲精品国产第一综合99久久 | 亚洲成人播放器 | 中文字幕在线播放不卡 | 99精品亚洲国产精品久久不卡 | 亚洲视频国产视频 | 亚欧洲精品在线视频免费观看 | 国产精品美女久久久久aⅴ国产馆 | 日韩精品二区 | 亚洲国产高清高潮精品美女 | 日韩欧美久久精品 |