แปลง timestamp ให้เป็นรูปแบบวันที่ภาษาไทย ติดตรงปี พ.ศ. ที่ยังไม่ได้
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา แปลง timestamp ให้เป็นรูปแบบวันที่ภาษาไทย ติดตรงปี พ.ศ. ที่ยังไม่ได้
แปลง timestamp ให้เป็นรูปแบบวันที่ภาษาไทย ติดตรงปี พ.ศ. ที่ยังไม่ได้
Copy
<?php $thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์"); $thai_month_arr=array( "0"=>"", "1"=>"มกราคม", "2"=>"กุมภาพันธ์", "3"=>"มีนาคม", "4"=>"เมษายน", "5"=>"พฤษภาคม", "6"=>"มิถุนายน", "7"=>"กรกฎาคม", "8"=>"สิงหาคม", "9"=>"กันยายน", "10"=>"ตุลาคม", "11"=>"พฤศจิกายน", "12"=>"ธันวาคม" ); $thai_month_arr_short=array( "0"=>"", "1"=>"ม.ค.", "2"=>"ก.พ.", "3"=>"มี.ค.", "4"=>"เม.ษ.", "5"=>"พ.ค.", "6"=>"มิ.ย.", "7"=>"ก.ค.", "8"=>"ส.ค.", "9"=>"ก.ย.", "10"=>"ต.ค.", "11"=>"พ.ย.", "12"=>"ธ.ค." ); function thai_date_and_time($time){ // 19 ??????? 2556 ???? 10:10:43 global $thai_day_arr,$thai_month_arr; $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:s",$time); return $thai_date_return; } function thai_date_and_time_short($time){ // 19 ?.?. 2556 10:10:4 global $thai_day_arr,$thai_month_arr_short; $thai_date_return.=date("j",$time); $thai_date_return.=" ".$thai_month_arr_short[date("n",$time)]; $thai_date_return.= " ".(date("Y",$time)+543); $thai_date_return.= " ".date("H:i:s",$time); return $thai_date_return; } function thai_date_short($time){ // 19 ?.?. 2556 global $thai_day_arr,$thai_month_arr_short; $thai_date_return.=date("j",$time); $thai_date_return.=" ".$thai_month_arr_short[date("n",$time)]; $thai_date_return.= " ".(date("Y",$time)+543); return $thai_date_return; } function thai_date_fullmonth($time){ // 19 ??????? 2556 global $thai_day_arr,$thai_month_arr; $thai_date_return.=date("j",$time); $thai_date_return.=" ".$thai_month_arr[date("n",$time)]; $thai_date_return.= " ".(date("Y",$time)+543); return $thai_date_return; } function thai_date_short_number($time){ // 19-12-56 global $thai_day_arr,$thai_month_arr; $thai_date_return.=date("d",$time); $thai_date_return.="-".date("m",$time); $thai_date_return.= "-".substr((date("Y",$time)+543),-2); return $thai_date_return; }
//$dateData="2559-6-14"; $dateData="2016-6-14"; echo thai_date_and_time(strtotime($dateData)); ?>ผลที่แสดงตัวแปร $dateData ออกมาเป็น: 14 มิถุนายน 2016 ซึ่งแสดงผลได้ถูกต้อง แต่ผมติดปัญหาตรงที่ค่า $dateData ผมเก็บค่าในฐานข้อมูลเป็นปี พ.ศ. คือ 2559-6-14 ซึ่งตอนแสดงผลออกมามันผิดพลาดเป็น 1 มกราคม 2513 รบกวนช่วยแนะนำวิธีแปลงค่า timestamp ให้เป็นภาษาไทย โดยที่ยังคงเป็นปี พ.ศ. เหมือนเดิมด้วยครับ.
Giggstar
49.230.189.xxx
14-06-2017
23:20:51
คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ