0

有没有办法使用 Zend Locale 转换时间,比如 17:00 到 5:00 pm?

我已经按原样尝试了文档中的方法(有错字),但它不起作用。它给出了错误'无法使用'dd.MM.yyyy'(M <> y)解析日期'13:44:42'

$locale = new Zend_Locale('de_AT');
if (Zend_Locale_Format::getTime('13:44:42',
                            array('date_format' =>
                                      Zend_Locale_Format::STANDARD,
                                  'locale' => $locale))) {
    print "time";
} else {
    print "not a time";
}

然后我尝试了一个两步法,首先获取当前语言环境的时间格式,然后在 getTime 函数中使用它。

$locale = new Zend_Locale('en_US');
$tf = Zend_Locale_Format::getTimeFormat($locale);
$test = Zend_Locale_Format::getTime('17:00', array('date_format' => $tf, 'locale' => $locale));

这会返回一个结果,但只会给我我所拥有的

array('date_format'=>'h:mm:ss a', 'locale'=>'en_US', 'hour'=>'17', 'minute'=>'00')

有什么东西可以将时间转换为我试图解析的实际语言环境吗?

4

1 回答 1

0

您需要使用Zend_Date区域设置来获取所需格式的日期。

$date    = new Zend_Date(); // Default ISO format type & en_US
// Set the time and pass the format I am using to set the time
$date->setTime('17:00:00', 'HH:mm:ss'); 
echo $date; // Jul 15, 2011 5:00:00 PM

编辑

更多关于如何Zend_Locale使用Zend_Date

$locale = new Zend_Locale('de_AT');
echo  $date->toString(Zend_Locale_Format::getTimeFormat($locale)) ; // 17:00:00
$locale = new Zend_Locale('en_US');
echo  $date->toString(Zend_Locale_Format::getTimeFormat($locale)) ; // 5:00:00 PM
于 2011-07-15T16:01:11.537 回答