Php 我能';不要在课堂上翻译日期
为了用不同的语言/格式翻译日期,我写了一个类。很抱歉,我重新发布了这个问题,因为上次我发布它时,我失去了互联网连接,人们离开了线程 这是全班同学Php 我能';不要在课堂上翻译日期,php,class,date,translate,Php,Class,Date,Translate,为了用不同的语言/格式翻译日期,我写了一个类。很抱歉,我重新发布了这个问题,因为上次我发布它时,我失去了互联网连接,人们离开了线程 这是全班同学 class GetDateTime { private $_text_en_US = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "January", "February", "March", "April", "May
class GetDateTime {
private $_text_en_US = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "January", "February", "March", "April", "May","June", "July", "August", "September","October", "November", "December");
private $_text_fr_FR = array("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche", "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
public function getDateTime($format='d/m/Y', $timestamp, $locale='fr_FR') {
switch ($format) {
case 'd/m/Y':
case 'm/d/Y':
return date($format, $timestamp);
break;
case 'l d F Y':
return str_replace($_text_en_US, ${'_text_'.$locale}, date($format, $timestamp));
break;
}
}
}
…我如何称呼它:
include_once (BASE_DIR.'/lib/dateTime.class.php');
$dateTime = new GetDateTime();
事实上,当我打电话时,根本没有翻译:
echo $dateTime->getDateTime('l d F Y', time());
作为
getDateTime
方法的第二个参数,您需要一个timestamp
,但传递的是date()
函数的结果,该函数是空字符串。将其替换为time()
函数
echo $dateTime->getDateTime('l d F Y', time());
编辑:我怎么会错过那个!您引用的是局部变量,而不是对象的属性。在上一个
案例中使用$this
关键字
条件:
return str_replace($this->_text_en_US, $this->{'_text_'.$locale}, date($format, $timestamp));
作为
getDateTime
方法的第二个参数,您需要一个timestamp
,但传递的是date()
函数的结果,该函数是空字符串。将其替换为time()
函数
echo $dateTime->getDateTime('l d F Y', time());
编辑:我怎么会错过那个!您引用的是局部变量,而不是对象的属性。在上一个
案例中使用$this
关键字
条件:
return str_replace($this->_text_en_US, $this->{'_text_'.$locale}, date($format, $timestamp));
作为
getDateTime
方法的第二个参数,您需要一个timestamp
,但传递的是date()
函数的结果,该函数是空字符串。将其替换为time()
函数
echo $dateTime->getDateTime('l d F Y', time());
编辑:我怎么会错过那个!您引用的是局部变量,而不是对象的属性。在上一个
案例中使用$this
关键字
条件:
return str_replace($this->_text_en_US, $this->{'_text_'.$locale}, date($format, $timestamp));
作为
getDateTime
方法的第二个参数,您需要一个timestamp
,但传递的是date()
函数的结果,该函数是空字符串。将其替换为time()
函数
echo $dateTime->getDateTime('l d F Y', time());
编辑:我怎么会错过那个!您引用的是局部变量,而不是对象的属性。在上一个
案例中使用$this
关键字
条件:
return str_replace($this->_text_en_US, $this->{'_text_'.$locale}, date($format, $timestamp));
那怎么办?您可以设置语言环境设置并获取翻译日期
<?php
setlocale(LC_TIME, "fr_FR");
echo strftime("Today is %A (in French) and the date is %B %d, %Y");
// Outputs something like that: Today is mercredi (in French) and the date is novembre 13, 2013
?>
那怎么办?您可以设置语言环境设置并获取翻译日期
<?php
setlocale(LC_TIME, "fr_FR");
echo strftime("Today is %A (in French) and the date is %B %d, %Y");
// Outputs something like that: Today is mercredi (in French) and the date is novembre 13, 2013
?>
那怎么办?您可以设置语言环境设置并获取翻译日期
<?php
setlocale(LC_TIME, "fr_FR");
echo strftime("Today is %A (in French) and the date is %B %d, %Y");
// Outputs something like that: Today is mercredi (in French) and the date is novembre 13, 2013
?>
那怎么办?您可以设置语言环境设置并获取翻译日期
<?php
setlocale(LC_TIME, "fr_FR");
echo strftime("Today is %A (in French) and the date is %B %d, %Y");
// Outputs something like that: Today is mercredi (in French) and the date is novembre 13, 2013
?>
@perdeu:你读了我写的吗?@perdeu:你读了我写的吗?@perdeu:你读了我写的吗?@perdeu:你读了我写的吗?对不起,我犯了一个错误。我的意思是,当然是时间()而不是日期()。还是一样的问题。那么告诉我,输出是什么?它是空的还是未更改的字符串(带有英文月份名称)?它是未更改的字符串。(未翻译)请参阅我的编辑。我希望这次能有所帮助,明白了!我真丢脸。。。非常感谢matewka,你让我开心!;-)对不起,我犯了一个错误。我的意思是,当然是时间()而不是日期()。还是一样的问题。那么告诉我,输出是什么?它是空的还是未更改的字符串(带有英文月份名称)?它是未更改的字符串。(未翻译)请参阅我的编辑。我希望这次能有所帮助,明白了!我真丢脸。。。非常感谢matewka,你让我开心!;-)对不起,我犯了一个错误。我的意思是,当然是时间()而不是日期()。还是一样的问题。那么告诉我,输出是什么?它是空的还是未更改的字符串(带有英文月份名称)?它是未更改的字符串。(未翻译)请参阅我的编辑。我希望这次能有所帮助,明白了!我真丢脸。。。非常感谢matewka,你让我开心!;-)对不起,我犯了一个错误。我的意思是,当然是时间()而不是日期()。还是一样的问题。那么告诉我,输出是什么?它是空的还是未更改的字符串(带有英文月份名称)?它是未更改的字符串。(未翻译)请参阅我的编辑。我希望这次能有所帮助,明白了!我真丢脸。。。非常感谢matewka,你让我开心!;-)