วันอังคารที่ 6 พฤษภาคม พ.ศ. 2557

php แปลง วันเดือนปี เป็นแบบวันที่ไทย & number format

<?php
// กำหนดการแสดงผลตัวเลข number format
function digi2($num1){
$num = number_format($num1,2);
return $num;
}
function digi($num2){
$num3 = number_format($num2);
return $num3;
}

// แปลงวันที่แบบสากล เป็นแบบไทย
$thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$thai_month_arr=array(
"0"=>"",
"1"=>"มกราคม",
"2"=>"กุมภาพันธ์",
"3"=>"มีนาคม",
"4"=>"เมษายน",
"5"=>"พฤษภาคม",
"6"=>"มิถุนายน",
"7"=>"กรกฎาคม",
"8"=>"สิงหาคม",
"9"=>"กันยายน",
"10"=>"ตุลาคม",
"11"=>"พฤศจิกายน",
"12"=>"ธันวาคม"
);
function thai_date($time){
global $thai_day_arr,$thai_month_arr;
//$thai_date_return="วัน".$thai_day_arr[date("w",$time)];
$thai_date_return = date("j",$time);
$thai_date_return.= " ".$thai_month_arr[date("n",$time)];
$thai_date_return.= " ".(date("Y",$time)+543);
//$thai_date_return.= "  ".date("H:i",$time)." น.";
return $thai_date_return;
}
function thai_sdate($time){
global $thai_day_arr,$thai_month_arr;
//$thai_sdate_return="วัน".$thai_day_arr[date("w",$time)];
$thai_sdate_return = date("j",$time);
$thai_sdate_return.= " ".$thai_month_arr[date("n",$time)];
//$thai_date_return.= " พ.ศ.".(date("Y",$time)+543);
//$thai_date_return.= "  ".date("H:i",$time)." น.";
return $thai_sdate_return;
}

// การใช้งาน
  $dt1=strtotime($row_rs_report['dates']);  //กำหนดตัวแปล
   echo thai_date($dt1); //การแสดงผล

?>

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

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