2 พฤศจิกายน 2556

Learning PHP class : Thai Date/Time Function

ตัวอย่างการเขียน function ให้แสดงวันที่และเวลาในรูปแบบของภาษาไทย

<?php
02.function DateThai($strDate)
03.{
04.$strYear date("Y",strtotime($strDate))+543;
05.$strMonthdate("n",strtotime($strDate));
06.$strDaydate("j",strtotime($strDate));
07.$strHourdate("H",strtotime($strDate));
08.$strMinutedate("i",strtotime($strDate));
09.$strSecondsdate("s",strtotime($strDate));
10.$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
11.$strMonthThai=$strMonthCut[$strMonth];
12.return "$strDay $strMonthThai $strYear, $strHour:$strMinute";
13.}
14. 
15.$strDate "2008-08-14 13:42:44";
16.echo "ThaiCreate.Com Time now : ".DateThai($strDate);
17.?>


Screenshot

PHP datethai


แหล่งที่มา : http://www.thaicreate.com/php/php-thai-date-time-function.html

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

All me is mine. I'm Hunter Ying. :)