donglian1384 2013-11-13 15:28
浏览 38
已采纳

我无法通过课程翻译日期[重复]

This question already has an answer here:

I wrote a class in order to translate a date in different languages/format. I'm sorry, I repost this problem because last time I've posted it I lost my Internet connection and people left the thread...

Here is the full class...

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;  
        }
    }

}

...and how I call it :

include_once (BASE_DIR.'/lib/dateTime.class.php');
$dateTime = new GetDateTime();

The fact is it's not translated at all when I call :

echo $dateTime->getDateTime('l d F Y', time());
</div>
  • 写回答

2条回答 默认 最新

  • duananyantan04633 2013-11-13 15:32
    关注

    As the second argument of the getDateTime method you're expecting a timestamp but you're passing the result of date() function which is empty string. Replace it with time() function.

    echo $dateTime->getDateTime('l d F Y', time());
    

    EDIT:
    How could I have missed that! You're refering to local variables, not object's properties. Use $this keyword in your last case condition:

    return str_replace($this->_text_en_US, $this->{'_text_'.$locale}, date($format, $timestamp));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 SpringBoot+Vue3
  • ¥15 高额悬赏~绕过防火墙被针对了
  • ¥15 IT从业者的调查问卷
  • ¥65 LineageOs-21.0系统编译问题
  • ¥30 关于#c++#的问题,请各位专家解答!
  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)