首页/Home PHP Common Programming 一个PHP本地时间类

一个PHP本地时间类

PrintE-mail
Sunday, 20 January 2008 09:00  

该localDate类显示的时间格式为 "星期一, xxxxr年x月x日"

<?php
/**
* This class is used to show date in Chinese.
* Format: 星期一, 2008年1月1日
*
* @author Shelley Shyan
* @copyright http://www.phparch.cn
*/
class localDate
{
private
$weekDay;
private
$day;
private
$month;
private
$year;

/**
* Constructor
*/
public function __construct()
{
$this->weekDay = date("l");
$this->day = date("j");
$this->month = date("n");
$this->year = date("Y");
}

/**
* Translate into local language
*
* @return string weakDay
*/
public function getDay()
{
$nlDay = array (
'Monday' => '星期一',
'Tuesday' => '星期二',
'Wednesday' => '星期三',
'Thursday' => '星期四',
'Friday' => '星期五',
'Saturday' => '星期六',
'Sunday' => '星期天');

return
$nlDay[$this->weekDay];
}

/**
* Get date in "xxxx年x月x日" 格式
*
* @return string date
*/
public function buildDate()
{
$longDate = $this->year . '年' . $this->month . '月' . $this->day . '日';
return
$longDate;
}
}
?>


例子:
$myDate = new localDate();
echo
$myDate->getDay() . ', ' . $myDate->buildDate();
// this will output "星期三, 2008年1月1日"

 

回复

留个脚印儿吧.


回复