function strtotime_thai($str){
$str = preg_replace_callback('/\d{4}/',function($match){
return $match[0]-543;
},$str);
setlocale(LC_TIME, 'thai');
$format = '%d %B %Y %H:%M:%S';//d M Y H:i:s
$str = iconv('UTF-8','TIS-620',$str);//comment this line if $str is tis620
$result = strptime($str,$format);
if (empty($result)){
return false;
}
extract($result);
return mktime($tm_hour,$tm_min,$tm_sec,$tm_mon+1,$tm_mday,$tm_year+1900);
}
$phptime = strtotime_thai('19 ธันวาคม 2557 23:30:59');
echo date('d/m/Y H/i/s',$phptime);
วันเสาร์ที่ 8 มีนาคม พ.ศ. 2557
แปลงวันที่ไทยให้เป็นวันที่ของ php
แปลงวันที่ภาษาไทยให้เป็นวันที่ php ครับ
แต่ function นี้มีข้อจำกัดคือไม่สามารถใช้กับ host windows ได้ครับเพราะเรียกใช้ strptime ซึ่งไม่มีใน host windows
ป้ายกำกับ:
ภาษาไทย,
php function
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น