แปลง timestamp ให้เป็นรูปแบบวันที่ภาษาไทย ติดตรงปี พ.ศ. ที่ยังไม่ได้

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา แปลง timestamp ให้เป็นรูปแบบวันที่ภาษาไทย ติดตรงปี พ.ศ. ที่ยังไม่ได้

แปลง timestamp ให้เป็นรูปแบบวันที่ภาษาไทย ติดตรงปี พ.ศ. ที่ยังไม่ได้
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?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.="&nbsp;&nbsp;".$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.="&nbsp;&nbsp;".$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;  
}
1
2
3
4
5
//$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 14-06-2017 23:20:51

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ดูเนื้อหานี้เป็นแนวทาง

แนวทางการจัดรูปแบบข้อความวันที่ ให้อยู่ในรูปแบบมาตรฐาน ใน php 


ninenik 15-06-2017
 ความคิดเห็นที่ 2
ขอบคุณครับ.


giggstar 27-06-2017 04:44






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ