久久久久久久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)
主站蜘蛛池模板: 国产美女福利在线观看 | 免费看黄色片 | 国产精品久久久久999 | 国产精品久久久久久久久久免费看 | 国产精品99999| 超碰人人插| 亚洲女优在线播放 | 国产一区二区三区免费观看视频 | 成人激情视频 | 欧美激情免费在线 | 日本免费网 | a免费观看| 欧美不卡网站 | 午夜视频在线免费观看 | 久久久久久国产精品免费免费 | 久亚州在线播放 | 97起碰| 中文字幕在线观看第一页 | 9999视频 | 成年人在线观看 | 中国黄色在线视频 | 久久久久国产一区二区三区四区 | 91婷婷韩国欧美一区二区 | 亚洲三区在线 | 亚洲入口 | 亚洲国产精品视频一区 | 成人二区| 日本久久久一区二区三区 | 91精品中文字幕一区二区三区 | 在线看成人av | 精品国产一区二区三区成人影院 | 成人在线精品视频 | 毛片在线免费播放 | 久久久av中文字幕 | 免费国产一区 | 国产成人精品久久二区二区91 | 在线日韩欧美 | 久久噜噜噜精品国产亚洲综合 | 国产精品国产成人国产三级 | 亚洲一区二区三区四区视频 | 性色av网站 |