1 / 19

CHAPTER 6 Mathematical Functions and Date/Time Functions

CHAPTER 6 Mathematical Functions and Date/Time Functions. Agenda. ฟังก์ชันทางคณิตศาสตร์ ฟังก์ชันเกี่ยวกับวันที่และเวลา . ฟังก์ชันทางคณิตศาสตร์. ใช้สำหรับการคำนวณทางคณิตศาสตร์ ซึ่งมีอยู่หลายฟังก์ชัน. ฟังก์ชันทางคณิตศาสตร์. ฟังก์ชันทางคณิตศาสตร์. ฟังก์ชัน number_format( ). รูปแบบ

tolinka
Download Presentation

CHAPTER 6 Mathematical Functions and Date/Time Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER 6Mathematical Functions andDate/Time Functions

  2. Agenda • ฟังก์ชันทางคณิตศาสตร์ • ฟังก์ชันเกี่ยวกับวันที่และเวลา

  3. ฟังก์ชันทางคณิตศาสตร์ฟังก์ชันทางคณิตศาสตร์ ใช้สำหรับการคำนวณทางคณิตศาสตร์ ซึ่งมีอยู่หลายฟังก์ชัน

  4. ฟังก์ชันทางคณิตศาสตร์ฟังก์ชันทางคณิตศาสตร์

  5. ฟังก์ชันทางคณิตศาสตร์ฟังก์ชันทางคณิตศาสตร์

  6. ฟังก์ชัน number_format( ) รูปแบบ number_format(number,decimals,dec_point,thousands_sep); number คือ ค่าคงที่หรือตัวแปรที่นำมากำหนดรูปแบบ    decimals คือจำนวนจุดทศนิยมที่ต้องการ    dec_point คือ สัญลักษณ์ที่ใช้ในการกำหนดจุดทศนิยม   thosands_sep คือสัญลักษณ์ที่ใช้ในการคั่นหลักพัน

  7. ตัวอย่าง <? print sqrt(36); print “<br>”; $a = 2.0;$b = 0.0;  do {printf ("2<sup>%.0f</sup> = %.2f\n<BR>", $b, pow($a,$b));   $b++;  }while ($b < 5.0);print max(10, 5, 30, 15, 50, 45, 60); print “<br>”; print bindec(1110011); print “<br>”; $total = 125252.683526;print number_format($total, 2, '.', ','); print “<br>”; print number_format($total, 2, '#', '_'); ผลลัพธ์ 6 20 = 1.0021 = 2.0022 = 4.0023 = 8.0024 = 16.00 60 243 125,252.68125_252#68

  8. ฟังก์ชันเกี่ยวกับวันที่และเวลาฟังก์ชันเกี่ยวกับวันที่และเวลา • ฟังก์ชันแสดงวันที่และเวลาปัจจุบัน • ใช้สำหรับการนำข้อมูลวันเวลาปัจจุบันในเครื่องเซิร์ฟเวอร์ในขณะนั้นออกมาแสดงหรือใช้งาน เช่น วันที่สั่งซื้อสินค้า เวลาที่โพสต์ข้อความ เป็นต้น • รูปแบบ • date(“รูปแบบ”) • date(“รูปแบบ”,ข้อมูลวันเวลาtimestamp) • รูปแบบคือรหัสที่กำหนดรูปแบบ date ที่ต้องการ เช่นหากต้องการ • แบบ วัน/เดือน/ปีสามารถใส่เป็น d/m/y • timestampคือข้อมูลวันเวลาที่ได้จากคำสั่ง mktime หรือ • gmmktime • ถ้าไม่กำหนด timestamp จะเป็นการเอาวันเวลาจากปฏิทินและนาฬิกาในเครื่องเซิร์ฟเวอร์

  9. รหัสรูปแบบ

  10. รหัสรูปแบบ

  11. รหัสรูปแบบ

  12. ตัวอย่าง <? $date = date("วันที่ j เดือนที่ n ปี ค.ศ. Y") ; echo $date ; ?> ผลลัพธ์ วันที่ 1 เดือนที่ 1 ปี ค.ศ. 2008

  13. ตัวอย่าง <? echo “<br>d-m-y = ”,date(“d-m-y”); echo “<br>d/m/y = ”,date(“d/m/y”); echo “<br>l,d M y = ”,date(“l,d M y”); echo “<br>เวลา H:i:s = ”,date(“H:i:s”); echo “<br>เวลา h: a = ”,date(“h:i a”); ?> ผลลัพธ์ d-m-y = 22-09-07 d/m/y = 22/09/07 l,d M y = Saturday, 22 Sep 07 เวลา H:i:s = 15:36:31 เวลา h:i a = 03:36 pm

  14. ฟังก์ชันสร้างวันที่และเวลาฟังก์ชันสร้างวันที่และเวลา ใช้สำหรับสร้างข้อมูลวันเวลาโดยสามารถนำเอาค่าวันเวลาแต่ละส่วนมาประกอบกัน เช่นเครื่องเซิร์ฟเวอร์ที่อยู่ต่างประเทศ หรือเครื่องเซิร์ฟเวอร์ตั้งอยู่ในเมืองไทย แต่เวลาช้าหรือเร็วไป รูปแบบ mktime(ชม,นาที,วินาที,เดือน,วัน,ปี ค.ศ.) ตัวอย่าง mktime(10,5,2,8,11,2007)ในกรณีที่ต้องการให้เวลาไวขึ้นกว่าเดิม 1 ชม. 6 นาที ให้กำหนดคำสั่งดังนี้ mktime(10+1,5+6,2,8,11,2007)

  15. ฟังก์ชันรับข้อมูลวันเวลาจากระบบโดยอ้างอิงกับเวลามาตรฐาน Greenwich Mean Time(GMT) รูปแบบ gmdate(รหัสรูปแบบ) ค่าที่ได้จะเป็นวันเวลาของมาตรฐาน GMT ซึ่งช้ากว่าเวลาในประเทศไทยประมาณ 7 ชม. (Thai time : GMT + 0700)

  16. ตัวอย่าง <? $th=mktime(gmdate(“H”)+7,gmdate(“i”),gmdate(“m”),gmdate(“d”),gmdate(“Y”); $format=“d/m/y H:i a”; $str=date($format,$th); echo “<br>วันเวลาขณะนี้ : $str<br>”) $th=mktime(gmdate(“H”)+7,gmdate(“i”)+5,gmdate(“m”),gmdate(“d”),gmdate(“Y”); $str=date($format,$th); echo “<br>ถัดไปอีก 5 นาที : $str<br>”) $th=mktime(gmdate(“H”)+7,gmdate(“i”),gmdate(“m”),gmdate(“d”)+9,gmdate(“Y”); $str=date($format,$th); echo “<br>ถัดไปอีก 9 วัน : $str<br>”) $th=mktime(gmdate(“H”)+7,gmdate(“i”),gmdate(“m”)+1,gmdate(“d”),gmdate(“Y”); $str=date($format,$th); echo “<br>ถัดไปอีก 1 เดือน : $str<br>”); ?> ผลลัพธ์ วันเวลาขณะนี้ : 22/09/07 14:16 pm ถัดไปอีก 5 นาที : 22/09/07 14:21 pmวัน ถัดไปอีก 9 วัน : 22/09/07 14:16 pm ถัดไปอีก 1 เดือน : 22/09/07 14:16 pm

  17. ฟังก์ชันรับค่าวันและเวลาปัจจุบันฟังก์ชันรับค่าวันและเวลาปัจจุบัน ฟังก์ชัน getdate() เป็นฟังก์ชั่นที่ใช้แสดงผลของวันเวลาเช่นเดียวกับฟังก์ชั่น date() แต่จะแตกต่างกันตรงที่ ฟังก์ชั่น getdate() จะส่งค่าของวันหรือเวลามากับอินเด็กซ์ต่างๆของอาร์เรย์ ซึ่งมีอินเด็กซ์ต่างๆ ฟังก์ชันtime() เป็นฟังก์ชั่นที่ส่ง timestamp ของวัน/เวลาปัจจุบันในเครื่องกลับมาให้ ซึ่งฟังก์ชั่น time() นี้จะให้ค่าเป็นหน่วยของวินาที

  18. อินเด็กซ์ของอาร์เรย์ที่ใช้กับฟังก์ชัน getdate()

  19. ตัวอย่าง <? day = getdate(); echo $day['year']."<br>" ; echo $day['month'] ; ?> ผลลัพธ์ 2007 October

More Related