【发布时间】:2017-11-21 11:55:41
【问题描述】:
这段代码应该输出如下内容:
这一刻,你生活在国际日历开始后的2017年5月9日3时2分11秒。
不知道是什么问题。
date_default_timezone_set(//location...);
say_time();
function say_time()
{
$o = ' of the';
class time_value
{
public $t, $name, $display;
protected $n, $suf;
function __construct()
{
$this->display = " $this->n"."$this->suf"." $this->name";
$this->n = date($this->t,time());
switch ($this->n)
{
case 1:
$suf = 'st';
break;
case 2:
$suf = 'nd';
break;
case 3:
$suf = 'rd';
break;
default:
$suf = 'nth';
break;
}
}
}
$sec = new time_value;
$sec->t = 's';
$sec->name = 'seconds';
$min = new time_value;
$min->t = 'i';
$min->name = 'minutes';
$hr = new time_value;
$hr->t = 'G';
$hr->name = 'hours';
$day = new time_value;
$day->t = 'j';
$day->name = 'days';
$mon = new time_value;
$mon->t = 'n';
$mon->name = 'months';
$yr = new time_value;
$yr->t = 'Y';
$yr->name = 'years';
echo "You are, at this moment, living in the "
.$sec->display .$o
.$min->display .$o
.$hr ->display .$o
.$day->display .$o
.$mon->display .$o
.$yr ->display .
" since the begining of the International calender.";
echo $sec->display;
}
【问题讨论】:
-
为什么要在函数中使用类?