<?
/*
***Class Name : TDConv
***Version : 1.5
***Description : This is the Easy way to Show a Dynamic Thai or English date on web page in normal styles such as
*** "dd-mm-yyy" which will show Monday 13 August 2001.
*** not only it's flexible for define any syntax which you like.and also can add or change your local language. .
**Usage : There are two variables to use this class ==> newTDConv($format, $country)
*** To define $format you must use only three letter d,m,yy respectly like this "d-m-yy"
*** "dd-mm-yyy" , "dds-mm-yyy", "d"," m" , " yy" etc.
*** To define $country you must select three variable "en" ," th" ," help" the details as following:
*** "en" stand for show english date, "th" stand for show thai date. "help" show examples.
***
*** Put the three lines as below in your php file. :
***
*** include ("newTDConv.php");
*** $show_date = new newTDConv("dd-mm-yyyy","en");
*** echo "$show_date->Show_Date" ;
*** the result is --> Monday 13 August 2001
***Author : @2001, Mr.Satit Phermsawang
***E-mail :satit@wimol.ac.th
***Author Note : Please feel free to used and modified. if it's usefully for you Don't forget to let me know.
*/
CLass newTDConv {
/*
**Define properties
*/
var $Get_Value ;
var $Get_Date ;
var $Show_Date ;
/*
** methods
*/
function newTDConv($Format,$Country) {
@list ($F, $M, $L) = split ('[/.-]', $Format);
$this->Get_Value=array($F,$M,$L);
switch ($Country) {
case "th":
$dayname=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์" ,"เสาร์");
$monthname=array(
"Thai_long"=>array(1=>"มกราคม","กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม",
"มิถุนายน","กรกฎาคม","สิงหาคม", "กันยายน","ตุลาคม","พฤศจิกายน",
"ธันวาคม"),
"Thai_short"=>array(1=>"ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.", "มิ.ย.","ก.ค.","ส.ค.",
"ก.ย.", "ต.ค.","พ.ย.", "ธ.ค."),
);
while ( list($key, $val) = each($this->Get_Value) ) {
switch (trim($val)) {
case "d" : //d,ds, dds do the samething.
case "ds" :
case "dds" : $this->Get_Date=date("j") ; break ;
case "dd" :
$d_D=$dayname[date("w")];
$d_DD=" ที่ ".date("j") ;
$this->Get_Date= $d_D.$d_DD; break ;
case "m" : $this->Get_Date=$monthname["Thai_short"][date("n")]; break ;
case "mm" : $this->Get_Date=$monthname["Thai_long"][date("n")]; break ;
case "y" : $this->Get_Date=substr(date("Y")+543,2,2) ; break ;
case "yy" : $this->Get_Date=date("Y")+543 ; break ;
case "yyyy" :
$y_D="พ.ศ. " ;
$y_DD=date("Y")+543 ;
$this->Get_Date=$y_D.$y_DD ; break ;
default : $this->Get_Date=""; break;
}
$Result[] =$this->Get_Date ;
}
$this->Show_Date = implode(" ",$Result );
break ;
case ("en"):
while ( list($key, $val) = each($this->Get_Value) ) {
switch (trim($val)) {
case "d" : $this->Get_Date=date("j") ; break ;
case "ds" : $this->Get_Date=date("jS") ; break ;
case "dd" : $this->Get_Date=date("l j") ; break ;
case "dds" : $this->Get_Date=date("l jS") ; break ;
case "m" : $this->Get_Date=date("M") ; break ;
case "mm" : $this->Get_Date=date("F") ; break ;
case "y" :
case "yy" : $this->Get_Date=date("y") ; break ;
case "yyyy" : $this->Get_Date=date("Y") ; break ;
default : $this->Get_Date=""; break;
}
$Result[] =$this->Get_Date ;
}
$this->Show_Date = implode(" ",$Result );
break ;
default :
$syntax=array("d", "ds", "dd", "dds", "m", "mm", "y", "yy", "yyyy",
"d-mm", "mm-yyyy", "yyyy", "d-m-yy" ,"ds--m-yy", "d-m-yyyy",
"ds-m-yyyy", "d-mm-yyyy", "ds-mm-yyyy ", "dd-mm-yyyy", "dds-mm-yyyy", "mm-d-yyyy",
"mm-ds -yyyy" ) ;
?>
<h2>The Sample of TDConv Class v.1.5 Syntax Usage :<br>
(by, Mr.Satit Phermsawang <a href="mailto:satit@wimol.ac.th">e-mail: satit@wimol.ac.th</a>)</h2>
<table cellspacing="2" cellpadding="2" border="1">
<tr align=center>
<td><b>No. </b></td>
<td><b>Syntax </b></td>
<td ><b>Thai</b></td>
<td><b>English</b></td>
</tr>
<? foreach ($syntax as $key=> $value) { ?>
<tr>
<td><? echo$key+1 .".<br>" ; ?></td>
<td><? echo """.$value."" <br>" ; ?></td>
<td><? $show_date_th = new newTDConv($value,"th");
echo "$show_date_th->Show_Date <br>" ; ?></td>
<td><? $show_date_en = new newTDConv($value,"en");
echo "$show_date_en->Show_Date <br>" ; ?></td>
</tr>
<?
}
?>
</table>
<?
break;
}
}
}
?> |