Skip to content

Instantly share code, notes, and snippets.

@M4R14
Created November 24, 2016 23:58
Show Gist options
  • Select an option

  • Save M4R14/82107d792f69a8ad150fa71cc0a670bc to your computer and use it in GitHub Desktop.

Select an option

Save M4R14/82107d792f69a8ad150fa71cc0a670bc to your computer and use it in GitHub Desktop.
<?php
function DateThai($strDate){
$strMonthCut = Array("", "ม.ค.", "ก.ม.", "มี.ค.","ม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$inputDate = array(
'year' => date("Y",strtotime($strDate))+543,
'month' => date("n",strtotime($strDate)),
'day' => date("j",strtotime($strDate)),
'hour' => date("H",strtotime($strDate)),
'minute' => date("i",strtotime($strDate)),
'seconds' => date("s",strtotime($strDate)),
'monthThai' => $strMonthCut[date("n",strtotime($strDate))],
);
if(isset($strDate)){
if ($inputDate['hour'] == "00" || $inputDate['hour'] == "0") {
$strNew = $inputDate['day'] ." ". $inputDate['monthThai'] ." ". $inputDate['year'];
} else {
$strNew = $inputDate['day'] ." ". $inputDate['monthThai'] ." ". $inputDate['year'] ." เวลา ". $inputDate['hour'] .":". $inputDate['seconds'];
}
}else {
$strNew = null;
}
return $strNew;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment