ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programming[php]ช่วยดูฟังชั่นนี้หน่อยครับ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: [php]ช่วยดูฟังชั่นนี้หน่อยครับ  (อ่าน 550 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
GillBate
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 160
ออฟไลน์ ออฟไลน์

กระทู้: 1,236



ดูรายละเอียด
« เมื่อ: 21 เมษายน 2010, 12:22:01 »

 Tongue ไปเอาฟังชั่นแปลงวินาทีเป็น "ชั่วโมง:นาที:วินาที" มาอ่ะครับ ทีนี้ผมเพิ่มแบบเป็นวันเข้าไปด้วย ไม่รู้ถูกรึเปล่า(ถึงมันจะรันออกมาเหมือนถูกก็ตาม) ช่วยตรวจดูให้หน่อยนะครับ

อันนี้ของเขาครับ
โค๊ด:
function sec2hms ($sec, $padHours = false) 
  {

    // holds formatted string
    $hms = "";
   
    // there are 3600 seconds in an hour, so if we
    // divide total seconds by 3600 and throw away
    // the remainder, we've got the number of hours
    $hours = intval(intval($sec) / 3600);

    // add to $hms, with a leading 0 if asked for
    $hms .= ($padHours)
          ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
          : $hours. ':';
     
    // dividing the total seconds by 60 will give us
    // the number of minutes, but we're interested in
    // minutes past the hour: to get that, we need to
    // divide by 60 again and keep the remainder
    $minutes = intval(($sec / 60) % 60);

    // then add to $hms (with a leading 0 if needed)
    $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';

    // seconds are simple - just divide the total
    // seconds by 60 and keep the remainder
    $seconds = intval($sec % 60);

    // add to $hms, again with a leading 0 if needed
    $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);

    // done!
    return $hms;
   
  }

?>

อันนี้ของผมที่เพิ่มการหาจำนวนวันเข้ามา
โค๊ด:
function sec2hms ($sec, $padHours = false) 
  {


    $hms = "";
   
    //เพิ่มมาตรงนี้แหละครับ
$days = intval(intval($sec) / (3600*24));
$hms .= ($padHours)
          ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
          : $days. ':';
   
   //นอกนั้นปกติครับ แค่แก้ค่าแสดงตัวเลขเฉยๆ
    $hms .= ($padHours)
          ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
          : $hours. ':';
     
    $minutes = intval(($sec / 60) % 60);

   $hms .= str_pad($minutes, 1, "0", STR_PAD_LEFT). ':';

    $seconds = intval($sec % 60);

   
    $hms .= str_pad($seconds, 1, "0", STR_PAD_LEFT);

    return $hms;
   
  }
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์